group

package module
v0.0.0-...-5abfed9 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 9 Imported by: 1

README

gin-group

自动绑定 gin 接口

Documentation

Index

Constants

View Source
const (
	MethodGet     = "Get"
	MethodHead    = "Head"
	MethodPost    = "Post"
	MethodPut     = "Put"
	MethodPatch   = "Patch" // RFC 5789
	MethodDelete  = "Delete"
	MethodConnect = "Connect"
	MethodOptions = "Options"
	MethodTrace   = "Trace"
)
View Source
const (
	Colon    = "Colon"
	Asterisk = "Asterisk"
)
View Source
const UserKey string = "__user__"

Variables

View Source
var MethodEXP = regexp.MustCompile("^(" + strings.Join(AnyMethods, "|") + ")(\\w+)")
View Source
var NewResponse = func() Response {
	return new(DefaultResponse)
}

Functions

func Abort

func Abort(ctx *gin.Context, data any, err Error)

func CORS

func CORS(ctx *gin.Context)

解决跨域问题

参考: https://blog.csdn.net/u011866450/article/details/126958238

func Default

func Default(group Group) (r *gin.Engine)

func GetUser

func GetUser[U any](ctx *gin.Context) (u U)

GetUser returns the user as type U.

func NameOfFunction

func NameOfFunction(any) string

func NameOfHandler

func NameOfHandler(fn HandlerFunc) string

func New

func New(group Group) (r *gin.Engine)

func ParsePath

func ParsePath(path string) string

func SetUser

func SetUser(ctx *gin.Context, user any)

func SplitHandlerName

func SplitHandlerName(fn HandlerFunc) (method, path string)

func Static

func Static(s string) gin.HandlerFunc

Types

type Chain

type Chain []HandlerFunc

type DefaultResponse

type DefaultResponse struct {
	Code  int    `json:"code"`
	Error string `json:"error,omitempty"`
	Data  any    `json:"data,omitempty"`
}

func (*DefaultResponse) Set

func (r *DefaultResponse) Set(ctx *gin.Context, data any, err Error)

type Error

type Error interface {
	error
	Code() int
}

type ErrorWithCode

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

func AutoError

func AutoError(err error) (e ErrorWithCode)

func NewError

func NewError(code int, message string) ErrorWithCode

func (ErrorWithCode) Code

func (e ErrorWithCode) Code() int

func (ErrorWithCode) Error

func (e ErrorWithCode) Error() string

func (ErrorWithCode) Format

func (e ErrorWithCode) Format(a ...any) ErrorWithCode

type Group

type Group struct {
	Path        string
	Middlewares gin.HandlersChain
	Customize   func(gin.IRouter)
	Handlers    Chain
	Groups      []Group
}

func (*Group) Bind

func (group *Group) Bind(r gin.IRouter)

type HandlerFunc

type HandlerFunc func(ctx *gin.Context) (data any, err Error)

func (HandlerFunc) Handler

func (f HandlerFunc) Handler(ctx *gin.Context)

Call is a gin.HandlerFunc with receiver f.

type Response

type Response interface {
	Set(ctx *gin.Context, data any, err Error)
}

func SetResponse

func SetResponse(ctx *gin.Context, data any, err Error) (resp Response)

Jump to

Keyboard shortcuts

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