httputils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(ctx *gin.Context, f func() interface{})

func HandleResp

func HandleResp(ctx *gin.Context, resp any)

func NewBadRequestError

func NewBadRequestError(code int, err string) error

func NewError

func NewError(status, code int, msg string) error

func NewForbiddenError

func NewForbiddenError(code int, err string) error

func NewInternalServerError

func NewInternalServerError(code int, err string) error

func NewNotFoundError

func NewNotFoundError(code int, err string) error

func NewUnauthorizedError

func NewUnauthorizedError(code int, err string) error

func RequestID

func RequestID(ctx context.Context) string

Types

type Error

type Error struct {
	Status    int    `json:"-"`
	Code      int    `json:"code"`
	Msg       string `json:"msg"`
	RequestID string `json:"request_id,omitempty"`
}

func (*Error) Error

func (j *Error) Error() string

type JSONResponse

type JSONResponse struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type PageRequest

type PageRequest struct {
	// Deprecated 请使用方法GetPage
	Page int `form:"page" json:"page"`
	// Deprecated 请使用方法GetSize
	Size int `form:"size" json:"size"`
	// Deprecated 请使用方法GetSort
	Sort string `form:"sort" json:"sort"`
	// Deprecated 请使用方法GetOrder
	Order string `form:"order" json:"order"`
}

PageRequest 使用UnmarshalJSON的方法来反序列化,避免使用用户传递的page和limit

func (*PageRequest) GetLimit

func (p *PageRequest) GetLimit() int

func (*PageRequest) GetOffset

func (p *PageRequest) GetOffset() int

func (*PageRequest) GetOrder added in v1.1.0

func (p *PageRequest) GetOrder() string

func (*PageRequest) GetPage

func (p *PageRequest) GetPage() int

func (*PageRequest) GetSize

func (p *PageRequest) GetSize() int

func (*PageRequest) GetSort added in v1.1.0

func (p *PageRequest) GetSort() string

type PageResponse

type PageResponse[T any] struct {
	List  []T   `json:"list"`
	Total int64 `json:"total"`
}

Jump to

Keyboard shortcuts

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