mygin

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: BSD-2-Clause Imports: 14 Imported by: 0

README

mygin

server package base on gin

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FormUrlEncode = formUrlEncode{}
)

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

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

func GetApp() *gin.Engine

func GetAppWithGroup

func GetAppWithGroup(prefix string) *gin.RouterGroup

func MapFormWithTag

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

func Pagination

func Pagination[T any](db *gorm.DB, req PageReq, resp *PageResp[T]) (err error)

func Pagination_other added in v1.0.6

func Pagination_other(db *gorm.DB, limit, page int, 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 RegisterBindParamError added in v1.0.9

func RegisterBindParamError(code int, httpCode int)

func RegisterServerError added in v1.0.9

func RegisterServerError(code int, httpCode int)

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func UriEncode added in v1.1.1

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

func UriEncodeReq added in v1.1.1

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

func UriEncodeReqResp added in v1.1.1

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

func UriEncodeResp added in v1.1.1

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

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

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

type IDs

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"`
	Page  int   `json:"page"`
	Limit int   `json:"limit"`
	List  []T   `json:"list"`
}

Jump to

Keyboard shortcuts

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