fox

package module
v0.0.0-...-df360ae Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var DefaultBinder binding.Binding = binding.JSON

DefaultBinder default binder

View Source
var DefaultErrorWriter io.Writer = os.Stderr

DefaultErrorWriter is the default io.Writer used by Gin to debug errors

View Source
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()
View Source
var ErrBindNonPointerValue = errors.New("can not bind to non-pointer value")

ErrBindNonPointerValue is required bind pointer

View Source
var (
	// LoggerContextKey logger save in gin context
	LoggerContextKey = "_fox-goinc/fox/logger/context/key"
)
View Source
var Query = &queryBinding{}

Query binder

View Source
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 Logger

func Logger(config ...LoggerConfig) gin.HandlerFunc

Logger middleware

func Mode

func Mode() string

Mode returns current fox mode.

func NewXResponseTimer

func NewXResponseTimer(key ...string) gin.HandlerFunc

NewXResponseTimer x-response-time middleware

func SetMode

func SetMode(value string)

SetMode sets gin mode according to input string.

Types

type Context

type Context struct {
	*gin.Context

	Logger logger.Logger
}

Context with engine

func (*Context) RequestBody

func (c *Context) RequestBody() (body []byte, err error)

RequestBody return request body bytes see c.ShouldBindBodyWith

func (*Context) TraceID

func (c *Context) TraceID() string

TraceID return request id

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 New

func New() *Engine

New return engine instance

func (*Engine) CORS

func (engine *Engine) CORS(config cors.Config)

CORS config

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.

func (*Engine) Use

func (engine *Engine) Use(middleware ...HandlerFunc)

Use middleware

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

type RouterConfigFunc func(router *Engine, embedFS ...embed.FS)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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