Documentation ¶
Index ¶
- Constants
- Variables
- func IsDebugging() bool
- func Logger(config ...LoggerConfig) gin.HandlerFunc
- func Mode() string
- func NewXResponseTimer(key ...string) gin.HandlerFunc
- func SetMode(value string)
- type Context
- type DefaultValidator
- type Engine
- type HandlerFunc
- type HandlersChain
- type LoggerConfig
- type RouterConfigFunc
- type RouterGroup
- func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc)
- func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
- func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (group *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (group *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (group *RouterGroup) Use(middleware ...HandlerFunc) gin.IRoutes
- type XResponseTimer
Constants ¶
const ( // DebugMode indicates gin mode is debug. DebugMode = gin.DebugMode // ReleaseMode indicates gin mode is release. ReleaseMode = gin.ReleaseMode // TestMode indicates gin mode is test. TestMode = gin.TestMode )
Variables ¶
var DefaultBinder binding.Binding = binding.JSON
DefaultBinder default binder
var DefaultErrorWriter io.Writer = os.Stderr
DefaultErrorWriter is the default io.Writer used by Gin to debug errors
var DefaultWriter io.Writer = os.Stdout
DefaultWriter is the default io.Writer used by Gin for debug output and middleware output like Logger() or Recovery(). Note that both Logger and Recovery provides custom ways to configure their output io.Writer. To support coloring in Windows use:
import "github.com/mattn/go-colorable" gin.DefaultWriter = colorable.NewColorableStdout()
var ErrBindNonPointerValue = errors.New("can not bind to non-pointer value")
ErrBindNonPointerValue is required bind pointer
var (
// LoggerContextKey logger save in gin context
LoggerContextKey = "_fox-goinc/fox/logger/context/key"
)
var Query = &queryBinding{}
Query binder
var Validate = validator.New()
Validate global validator
Functions ¶
func IsDebugging ¶
func IsDebugging() bool
IsDebugging returns true if the framework is running in debug mode. Use SetMode(gin.ReleaseMode) to disable debug mode.
func NewXResponseTimer ¶
func NewXResponseTimer(key ...string) gin.HandlerFunc
NewXResponseTimer x-response-time middleware
Types ¶
type Context ¶
Context with engine
func (*Context) RequestBody ¶
RequestBody return request body bytes see c.ShouldBindBodyWith
type DefaultValidator ¶
type DefaultValidator struct {
// contains filtered or unexported fields
}
DefaultValidator is the default implementation of Validator.
func (*DefaultValidator) Engine ¶
func (v *DefaultValidator) Engine() interface{}
Engine return validate
func (*DefaultValidator) ValidateStruct ¶
func (v *DefaultValidator) ValidateStruct(obj interface{}) error
ValidateStruct check struct
type Engine ¶
type Engine struct { *gin.Engine RouterGroup }
Engine for server
func (*Engine) Load ¶
func (engine *Engine) Load(f RouterConfigFunc, fs ...embed.FS)
Load router config
func (*Engine) NotFound ¶
func (engine *Engine) NotFound(handlers ...HandlerFunc)
NotFound adds handlers for NoRoute. It returns a 404 code by default.
type HandlerFunc ¶
type HandlerFunc interface{}
HandlerFunc is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but has a third parameter for the values of wildcards (path variables). func(){} func(ctx *Context) any { ... } func(ctx *Context) (any, err) { ... } func(ctx *Context, args *AutoBindingArgType) (any) { ... } func(ctx *Context, args *AutoBindingArgType) (any, err) { ... }
type HandlersChain ¶
type HandlersChain []HandlerFunc
HandlersChain defines a HandlerFunc slice.
func (HandlersChain) Last ¶
func (c HandlersChain) Last() HandlerFunc
Last returns the last handler in the chain. i.e. the last handler is the main one.
type LoggerConfig ¶
type LoggerConfig struct { // SkipPaths is an url path array which logs are not written. // Optional. SkipPaths []string }
LoggerConfig defines the config for Logger middleware.
type RouterConfigFunc ¶
RouterConfigFunc engine load router config func
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup is gin.RouterGroup wrapper
func (*RouterGroup) Any ¶
func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc)
Any registers a route that matches all the HTTP methods. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
func (*RouterGroup) DELETE ¶
func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) gin.IRoutes
DELETE is a shortcut for router.Handle("DELETE", path, handle).
func (*RouterGroup) GET ¶
func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) gin.IRoutes
GET is a shortcut for router.Handle("GET", path, handle).
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
Group creates a new router group. You should add all the routes that have common middlewares or the same path prefix. For example, all the routes that use a common middleware for authorization could be grouped.
func (*RouterGroup) HEAD ¶
func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) gin.IRoutes
HEAD is a shortcut for router.Handle("HEAD", path, handle).
func (*RouterGroup) Handle ¶
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) gin.IRoutes
Handle gin.Handle wrapper
func (*RouterGroup) OPTIONS ¶
func (group *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) gin.IRoutes
OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).
func (*RouterGroup) PATCH ¶
func (group *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) gin.IRoutes
PATCH is a shortcut for router.Handle("PATCH", path, handle).
func (*RouterGroup) POST ¶
func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) gin.IRoutes
POST is a shortcut for router.Handle("POST", path, handle).
func (*RouterGroup) PUT ¶
func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) gin.IRoutes
PUT is a shortcut for router.Handle("PUT", path, handle).
func (*RouterGroup) Use ¶
func (group *RouterGroup) Use(middleware ...HandlerFunc) gin.IRoutes
Use adds middleware to the group, see example code in GitHub.
type XResponseTimer ¶
type XResponseTimer struct { gin.ResponseWriter // contains filtered or unexported fields }
XResponseTimer wrap gin reponse writer add start time
func (*XResponseTimer) Write ¶
func (w *XResponseTimer) Write(b []byte) (int, error)
Write implement http.ResponseWriter
func (*XResponseTimer) WriteHeader ¶
func (w *XResponseTimer) WriteHeader(statusCode int)
WriteHeader implement http.ResponseWriter