apiwrap

package
v0.0.0-...-6730fbd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(ctx *gin.Context, err error)

func Wrap

func Wrap[T any](fn func(ctx *gin.Context) (T, error)) gin.HandlerFunc

func WrapWithBody

func WrapWithBody[T any, R any](fn func(ctx *gin.Context, req R) (T, error)) gin.HandlerFunc

Types

type ErrorResponseBody

type ErrorResponseBody struct {
	HttpCode int
	Message  string
}

func NewErrorResponseBody

func NewErrorResponseBody(httpCode int, message string) ErrorResponseBody

func (ErrorResponseBody) Error

func (er ErrorResponseBody) Error() string

type HttpCodeError

type HttpCodeError int

type ListVO

type ListVO[T any] struct {
	List []T `json:"list"`
}

func NewListVO

func NewListVO[T any](t []T) ListVO[T]

type Page

type Page struct {
	// 当前页
	PageNo int64 `form:"pageNo" binding:"required"`
	// 每页数量
	PageSize int64 `form:"pageSize" binding:"required"`
}

type PageVO

type PageVO[T any] struct {
	Page
	// 总页数
	TotalPages int64 `json:"totalPages"`
	// 总数量
	TotalCount int64 `json:"totalCount"`
	List       []T   `json:"list"`
}

func NewPageVO

func NewPageVO[T any](pageNo, pageSize, totalCount int64, list []T) *PageVO[T]

func (*PageVO[T]) SetTotalCountAndCalculateTotalPages

func (p *PageVO[T]) SetTotalCountAndCalculateTotalPages(totalCount int64)

type ResponseBody

type ResponseBody[T any] struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    T      `json:"data,omitempty"`
}

func NewResponseBody

func NewResponseBody[T any](code int, message string, data T) *ResponseBody[T]

func SuccessResponse

func SuccessResponse() *ResponseBody[any]

func SuccessResponseWithData

func SuccessResponseWithData[T any](data T) *ResponseBody[T]

func (ResponseBody[T]) Error

func (er ResponseBody[T]) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL