api

package
v0.0.0-...-a783adc Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SuccessResponse = ResponseBody[any]{
		Code:    http.StatusOK,
		Message: http.StatusText(http.StatusOK),
		Data:    nil,
	}
)

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 IdVO

type IdVO struct {
	Id string `json:"id"`
}

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" json:"pageNo" binding:"required"`
	// 每页数量
	PageSize int64 `form:"pageSize" json:"pageSize" binding:"required"`
}

type PageRequest

type PageRequest struct {
	Page
	// 排序字段
	Sorting
	// 搜索内容
	Search *string `form:"search,omitempty"`
}

func (*PageRequest) ValidateAndSetDefault

func (p *PageRequest) ValidateAndSetDefault()

type PageVO

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

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 SuccessResponseWithData

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

type Sorting

type Sorting struct {
	Filed *string `form:"sortFiled,omitempty"`
	Order *string `form:"sortOrder,omitempty"`
}

Jump to

Keyboard shortcuts

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