mygin

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: BSD-2-Clause Imports: 14 Imported by: 0

README

mygin

server package base on gin

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Body

func Body(ctx *gin.Context, thenFunc noReqNoRespThenFunc)

func BodyReq

func BodyReq[REQ any](ctx *gin.Context, req REQ, thenFunc reqNoRespThenFunc[REQ])

func BodyReqResp

func BodyReqResp[REQ, RESP any](ctx *gin.Context, req REQ, thenFunc thenFunc[REQ, RESP])

func BodyResp

func BodyResp[RESP any](ctx *gin.Context, thenFunc noReqRespThenFunc[RESP])

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func Cors added in v1.0.1

func Cors() gin.HandlerFunc

func Form

func Form(ctx *gin.Context, thenFunc noReqNoRespThenFunc)

func FormReq

func FormReq[REQ any](ctx *gin.Context, req REQ, thenFunc reqNoRespThenFunc[REQ])

func FormReqResp

func FormReqResp[REQ, RESP any](ctx *gin.Context, req REQ, thenFunc thenFunc[REQ, RESP])

func FormResp

func FormResp[RESP any](ctx *gin.Context, thenFunc noReqRespThenFunc[RESP])

func GetApp added in v1.0.1

func GetApp() *gin.Engine

func GetAppWithGroup added in v1.0.1

func GetAppWithGroup(prefix string) *gin.RouterGroup

func MapFormWithTag

func MapFormWithTag(ptr any, form map[string][]string, tag string) error

func Pagination

func Pagination(db *gorm.DB, req PageReq, count *int64, list any) (err error)

func Query

func Query(ctx *gin.Context, thenFunc noReqNoRespThenFunc)

func QueryReq

func QueryReq[REQ any](ctx *gin.Context, req REQ, thenFunc reqNoRespThenFunc[REQ])

func QueryReqResp

func QueryReqResp[REQ, RESP any](ctx *gin.Context, req REQ, thenFunc thenFunc[REQ, RESP])

func QueryResp

func QueryResp[RESP any](ctx *gin.Context, thenFunc noReqRespThenFunc[RESP])

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func WriteBindCodeSimple

func WriteBindCodeSimple(httpCode int, ctx *gin.Context, str string)

func WriteBindError

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

func WriteJSON

func WriteJSON(ctx *gin.Context, code, httpCode int, msg string, err error, data any)

func WriteJSONSimple

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

func WriteServerErrorJSON

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

func WriteSuccessJSON

func WriteSuccessJSON(ctx *gin.Context, data any)

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

func NewError

func NewError(error string) *Error

func NewErrorWithCode

func NewErrorWithCode(error string, code int) *Error

func NewErrorWithCodes

func NewErrorWithCodes(error string, httpCode int, code int) *Error

func NewErrorWithHttpCode

func NewErrorWithHttpCode(error string, httpCode int) *Error

func (*Error) Error

func (e *Error) Error() string

type ID added in v1.0.2

type ID struct {
	ID int `json:"id" form:"id" validate:"min(1,入参ID不能为空)"`
}

type IDs added in v1.0.2

type IDs struct {
	IDs []int `json:"ids" form:"ids" validate:"minlength(1,入参ID不能为空)"`
}

type PageReq

type PageReq struct {
	Limit int `form:"limit" validate:"min(1,无效的分页数据)"`
	Page  int `form:"page"`
}

type PageResp

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

Jump to

Keyboard shortcuts

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