Documentation ¶
Index ¶
- Constants
- Variables
- func GetRePath(str string) *regexp.Regexp
- func Handler(e *Engine, fun func(*Context)) gin.HandlerFunc
- func MatchPath(regPath, rPath string) bool
- type Config
- type Configurer
- type Context
- type Engine
- type Error
- type ErrorTransformFunc
- type FieldError
- type HTMLRender
- type HandlerFunc
- type Logger
- type Middleware
- type MiddlewareWrapper
- type Middlewares
- type MiddlewaresWrapper
- type Plugin
- type Router
- type RouterGroup
- type RouterGroupWrapper
- func (g *RouterGroupWrapper) AddMiddleware(names ...string) *RouterGroupWrapper
- func (g *RouterGroupWrapper) AddRouter(routers ...interface{}) *RouterGroupWrapper
- func (g *RouterGroupWrapper) Middleware() []string
- func (g *RouterGroupWrapper) Path() string
- func (g *RouterGroupWrapper) Routers() []interface{}
- func (g *RouterGroupWrapper) SetMiddleware(names ...string) *RouterGroupWrapper
- type RouterGroups
- type RouterGroupsWrapper
- type RouterWrapper
- func (r *RouterWrapper) AddAfterMiddleware(names ...string) *RouterWrapper
- func (r *RouterWrapper) AddBeforeMiddleware(names ...string) *RouterWrapper
- func (r *RouterWrapper) AddMethod(method string) *RouterWrapper
- func (r *RouterWrapper) AfterMiddleware() []string
- func (r *RouterWrapper) BeforeMiddleware() []string
- func (r *RouterWrapper) Handler(c *Context)
- func (r *RouterWrapper) Methods() []string
- func (r *RouterWrapper) Path() string
- func (r *RouterWrapper) SetAfterMiddleware(names ...string) *RouterWrapper
- func (r *RouterWrapper) SetBeforeMiddleware(names ...string) *RouterWrapper
- type Static
- type Statics
- type Theme
Constants ¶
View Source
const PluginName = "gin"
Variables ¶
View Source
var ( ErrBadRequest = func() *Error { return NewError(http.StatusBadRequest) } ErrForbidden = func() *Error { return NewError(http.StatusForbidden) } ErrNotFound = func() *Error { return NewError(http.StatusNotFound) } ErrConflict = func() *Error { return NewError(http.StatusConflict) } ErrUnprocessableEntity = func() *Error { return NewError(http.StatusUnprocessableEntity) } ErrInternalServerError = func() *Error { return NewError(http.StatusInternalServerError) } ErrorTransform = DefaultErrorTransform )
Functions ¶
Types ¶
type Config ¶
type Config struct { // Mode gin mode according to input string: debug, release, test. Mode string `mapstructure:"mode" json:"mode,omitempty" bson:"mode,omitempty"` // Static files which serves from the given file system root. Static map[string]string `mapstructure:"static" json:"static,omitempty" bson:"static,omitempty"` // List of the middleware names (order will be preserved). Middleware []string `mapstructure:"middleware" json:"middleware,omitempty" bson:"middleware,omitempty"` // EnableDecoderUseNumber is used to call the UseNumber method on the JSON // Decoder instance. UseNumber causes the Decoder to unmarshal a number into an // any as a Number instead of as a float64. EnableDecoderUseNumber bool `` /* 126-byte string literal not displayed */ // EnableDecoderDisallowUnknownFields is used to call the DisallowUnknownFields method // on the JSON Decoder instance. DisallowUnknownFields causes the Decoder to // return an error when the destination is a struct and the input contains object // keys which do not match any non-ignored, exported fields in the destination. EnableDecoderDisallowUnknownFields bool `` /* 165-byte string literal not displayed */ // RedirectTrailingSlash enables automatic redirection if the current route can't be matched but a // handler for the path with (without) the trailing slash exists. // For example if /foo/ is requested but a route only exists for /foo, the // client is redirected to /foo with http status code 301 for GET requests // and 307 for all other request methods. RedirectTrailingSlash *bool `mapstructure:"redirect_trailing_slash" json:"redirect_trailing_slash,omitempty" bson:"redirect_trailing_slash,omitempty"` // RedirectFixedPath if enabled, the router tries to fix the current request path, if no // handle is registered for it. // First superfluous path elements like ../ or // are removed. // Afterwards the router does a case-insensitive lookup of the cleaned path. // If a handle can be found for this route, the router makes a redirection // to the corrected path with status code 301 for GET requests and 307 for // all other request methods. // For example /FOO and /..//Foo could be redirected to /foo. // RedirectTrailingSlash is independent of this option. RedirectFixedPath bool `mapstructure:"redirect_fixed_path" json:"redirect_fixed_path,omitempty" bson:"redirect_fixed_path,omitempty"` // HandleMethodNotAllowed if enabled, the router checks if another method is allowed for the // current route, if the current request can not be routed. // If this is the case, the request is answered with 'Method Not Allowed' // and HTTP status code 405. // If no other Method is allowed, the request is delegated to the NotFound // handler. HandleMethodNotAllowed bool `` /* 126-byte string literal not displayed */ // ForwardedByClientIP if enabled, client IP will be parsed from the request's headers that // match those stored at `(*gin.Engine).RemoteIPHeaders`. If no IP was // fetched, it falls back to the IP obtained from // `(*gin.Context).Request.RemoteAddr` ForwardedByClientIP *bool `mapstructure:"forwarded_by_client_ip" json:"forwarded_by_client_ip,omitempty" bson:"forwarded_by_client_ip,omitempty"` // UseRawPath if enabled, the url.RawPath will be used to find parameters. UseRawPath bool `mapstructure:"use_raw_path" json:"use_raw_path,omitempty" bson:"use_raw_path,omitempty"` // UnescapePathValues if true, the path value will be unescaped. // If UseRawPath is false (by default), the UnescapePathValues effectively is true, // as url.Path gonna be used, which is already unescaped. UnescapePathValues *bool `mapstructure:"unescape_path_values" json:"unescape_path_values,omitempty" bson:"unescape_path_values,omitempty"` // RemoveExtraSlash a parameter can be parsed from the URL even with extra slashes. // See the PR #1817 and issue #1644 RemoveExtraSlash bool `mapstructure:"remove_extra_slash" json:"remove_extra_slash,omitempty" bson:"remove_extra_slash,omitempty"` // RemoteIPHeaders list of headers used to obtain the client IP when // `(*gin.Engine).ForwardedByClientIP` is `true` and // `(*gin.Context).Request.RemoteAddr` is matched by at least one of the // network origins of list defined by `(*gin.Engine).SetTrustedProxies()`. RemoteIPHeaders []string `mapstructure:"remote_ip_headers" json:"remote_ip_headers,omitempty" bson:"remote_ip_headers,omitempty"` // TrustedPlatform if set to a constant of value gin.Platform*, trusts the headers set by // that platform, for example to determine the client IP TrustedPlatform string `mapstructure:"trusted_platform" json:"trusted_platform,omitempty" bson:"trusted_platform,omitempty"` // MaxMultipartMemory value of 'maxMemory' param that is given to http.Request's ParseMultipartForm // method call. MaxMultipartMemory int64 `mapstructure:"max_multipart_memory" json:"max_multipart_memory,omitempty" bson:"max_multipart_memory,omitempty"` // ContextWithFallback enable fallback Context.Deadline(), Context.Done(), Context.Err() and Context.Value() when Context.Request.Context() is not nil. ContextWithFallback bool `mapstructure:"context_with_fallback" json:"context_with_fallback,omitempty" bson:"context_with_fallback,omitempty"` }
func (*Config) InitDefaults ¶
func (g *Config) InitDefaults()
type Configurer ¶
type Error ¶
func DefaultErrorTransform ¶
func (*Error) AddInternal ¶
func (*Error) MarshalJSON ¶
func (*Error) SetInternal ¶
func (*Error) SetMessage ¶
type ErrorTransformFunc ¶
type FieldError ¶
type HTMLRender ¶
type HTMLRender struct {
// contains filtered or unexported fields
}
type HandlerFunc ¶
type HandlerFunc func(*Context)
type Middleware ¶
type Middleware interface { Name() string Middleware() HandlerFunc }
type MiddlewareWrapper ¶
type MiddlewareWrapper struct {
// contains filtered or unexported fields
}
func NewMiddlewareWrapper ¶
func NewMiddlewareWrapper(name string, handler HandlerFunc) MiddlewareWrapper
func (MiddlewareWrapper) Middleware ¶
func (w MiddlewareWrapper) Middleware() HandlerFunc
func (MiddlewareWrapper) Name ¶
func (w MiddlewareWrapper) Name() string
type Middlewares ¶
type Middlewares interface {
Middlewares() []interface{}
}
type MiddlewaresWrapper ¶
type MiddlewaresWrapper struct {
// contains filtered or unexported fields
}
func NewMiddlewaresWrapper ¶
func NewMiddlewaresWrapper(mdwr ...interface{}) MiddlewaresWrapper
func (MiddlewaresWrapper) Middlewares ¶
func (w MiddlewaresWrapper) Middlewares() []interface{}
type RouterGroup ¶
type RouterGroup interface { Path() string Routers() []interface{} }
type RouterGroupWrapper ¶
type RouterGroupWrapper struct {
// contains filtered or unexported fields
}
func NewRouterGroupWrapper ¶
func NewRouterGroupWrapper(path string, routers ...interface{}) *RouterGroupWrapper
func (*RouterGroupWrapper) AddMiddleware ¶
func (g *RouterGroupWrapper) AddMiddleware(names ...string) *RouterGroupWrapper
func (*RouterGroupWrapper) AddRouter ¶
func (g *RouterGroupWrapper) AddRouter(routers ...interface{}) *RouterGroupWrapper
func (*RouterGroupWrapper) Middleware ¶
func (g *RouterGroupWrapper) Middleware() []string
func (*RouterGroupWrapper) Path ¶
func (g *RouterGroupWrapper) Path() string
func (*RouterGroupWrapper) Routers ¶
func (g *RouterGroupWrapper) Routers() []interface{}
func (*RouterGroupWrapper) SetMiddleware ¶
func (g *RouterGroupWrapper) SetMiddleware(names ...string) *RouterGroupWrapper
type RouterGroups ¶
type RouterGroups interface {
RouterGroups() []interface{}
}
type RouterGroupsWrapper ¶
type RouterGroupsWrapper struct {
// contains filtered or unexported fields
}
func NewRouterGroupsWrapper ¶
func NewRouterGroupsWrapper(routerGroups ...interface{}) RouterGroupsWrapper
func (RouterGroupsWrapper) RouterGroups ¶
func (g RouterGroupsWrapper) RouterGroups() []interface{}
type RouterWrapper ¶
type RouterWrapper struct {
// contains filtered or unexported fields
}
func NewRouterWrapper ¶
func NewRouterWrapper(method, path string, handler HandlerFunc) *RouterWrapper
func (*RouterWrapper) AddAfterMiddleware ¶
func (r *RouterWrapper) AddAfterMiddleware(names ...string) *RouterWrapper
func (*RouterWrapper) AddBeforeMiddleware ¶
func (r *RouterWrapper) AddBeforeMiddleware(names ...string) *RouterWrapper
func (*RouterWrapper) AddMethod ¶
func (r *RouterWrapper) AddMethod(method string) *RouterWrapper
func (*RouterWrapper) AfterMiddleware ¶
func (r *RouterWrapper) AfterMiddleware() []string
func (*RouterWrapper) BeforeMiddleware ¶
func (r *RouterWrapper) BeforeMiddleware() []string
func (*RouterWrapper) Handler ¶
func (r *RouterWrapper) Handler(c *Context)
func (*RouterWrapper) Methods ¶
func (r *RouterWrapper) Methods() []string
func (*RouterWrapper) Path ¶
func (r *RouterWrapper) Path() string
func (*RouterWrapper) SetAfterMiddleware ¶
func (r *RouterWrapper) SetAfterMiddleware(names ...string) *RouterWrapper
func (*RouterWrapper) SetBeforeMiddleware ¶
func (r *RouterWrapper) SetBeforeMiddleware(names ...string) *RouterWrapper
type Static ¶
type Static interface { RelativePath() string FileSystem() http.FileSystem }
type Theme ¶
type Theme interface { Debug(debug bool) *et.Environment Global(global ...string) *et.Environment Load(ctx context.Context, name string) (*et.TemplateWrapper, error) }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.