Documentation
¶
Index ¶
- Constants
- Variables
- func BytesToString(b []byte) string
- func DefaultDecompressHandle(c *Context)
- func Dir(root string, listDirectory bool) http.FileSystem
- func InitSession()
- func IsDebugging() bool
- func StringToBytes(s string) (b []byte)
- type AppConfig
- type Body
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortWithError(code int, err error) *Error
- func (c *Context) AbortWithStatus(code int)
- func (c *Context) AsciiJSON(data interface{})
- func (c *Context) Body() []byte
- func (c *Context) ClientIP() (ip string)
- func (c *Context) DataJSON(args ...interface{})
- func (c *Context) DecodeJSONBody(v interface{}) error
- func (c *Context) DeleteSession(key string)
- func (c *Context) DownLoadFile(data []byte, filename string)
- func (c *Context) Download(data []byte)
- func (c *Context) Error(err error) *Error
- func (c *Context) File(filepath string)
- func (c *Context) FileAttachment(filepath, filename string)
- func (c *Context) Form(key string) string
- func (c *Context) FullPath() string
- func (c *Context) GetBool(key string, def ...bool) (bool, error)
- func (c *Context) GetCookie(name string) (string, error)
- func (c *Context) GetEngine() *Engine
- func (c *Context) GetFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (c *Context) GetFiles(key string) ([]*multipart.FileHeader, error)
- func (c *Context) GetFloat64(key string, def ...float64) (float64, error)
- func (c *Context) GetHeader(key string) string
- func (c *Context) GetIP() (ip string)
- func (c *Context) GetInt(key string, def ...int) (int, error)
- func (c *Context) GetInt16(key string, def ...int16) (int16, error)
- func (c *Context) GetInt32(key string, def ...int32) (int32, error)
- func (c *Context) GetInt64(key string, def ...int64) (int64, error)
- func (c *Context) GetInt8(key string, def ...int8) (int8, error)
- func (c *Context) GetKey(key string) (value interface{}, exist bool)
- func (c *Context) GetSession(key string) interface{}
- func (c *Context) GetString(key string, def ...string) string
- func (c *Context) GetStrings(key string, def ...[]string) []string
- func (c *Context) GetUint16(key string, def ...uint16) (uint16, error)
- func (c *Context) GetUint32(key string, def ...uint32) (uint32, error)
- func (c *Context) GetUint64(key string, def ...uint64) (uint64, error)
- func (c *Context) GetUint8(key string, def ...uint8) (uint8, error)
- func (c *Context) HTML(name string, data ...interface{})
- func (c *Context) Handler() HandlerFunc
- func (c *Context) HandlerName() string
- func (c *Context) HandlerNames() []string
- func (c *Context) Header(key, value string)
- func (c *Context) Host() string
- func (c *Context) IsAborted() bool
- func (c *Context) IsAjax() bool
- func (c *Context) IsProd() bool
- func (c *Context) IsWeChat() bool
- func (c *Context) IsWebsocket() bool
- func (c *Context) JSON(data interface{})
- func (c *Context) JSONP(callback string, data interface{})
- func (c *Context) KeyBool(key string) (b bool)
- func (c *Context) KeyDuration(key string) (d time.Duration)
- func (c *Context) KeyFloat64(key string) (f64 float64)
- func (c *Context) KeyInt(key string) (i int)
- func (c *Context) KeyInt64(key string) (i64 int64)
- func (c *Context) KeyString(key string) (s string)
- func (c *Context) KeyStringMap(key string) (sm map[string]interface{})
- func (c *Context) KeyStringMapString(key string) (sms map[string]string)
- func (c *Context) KeyStringMapStringSlice(key string) (smss map[string][]string)
- func (c *Context) KeyStringSlice(key string) (ss []string)
- func (c *Context) KeyTime(key string) (t time.Time)
- func (c *Context) KeyUint(key string) (ui uint)
- func (c *Context) KeyUint64(key string) (ui64 uint64)
- func (c *Context) MustGet(key string) interface{}
- func (c *Context) Next()
- func (c *Context) Param(key string) string
- func (c *Context) ParamInt(key string) (int, error)
- func (c *Context) ParamInt64(key string) (int64, error)
- func (c *Context) PureJSON(data interface{})
- func (c *Context) Query(key string) string
- func (c *Context) Redirect(code int, url string)
- func (c *Context) Referer() string
- func (c *Context) Render(code int, name string, data interface{})
- func (c *Context) SaveToFile(fromFile, toFile string) error
- func (c *Context) SecureJSON(data interface{})
- func (c *Context) ServerAsciiJSON(code int, data interface{})
- func (c *Context) ServerDataJSON(statusCode int, args ...interface{})
- func (c *Context) ServerHTML(code int, name string, data ...interface{})
- func (c *Context) ServerJSON(code int, data interface{})
- func (c *Context) ServerJSONP(code int, callback string, data interface{})
- func (c *Context) ServerPureJSON(code int, data interface{})
- func (c *Context) ServerSecureJSON(code int, data interface{})
- func (c *Context) ServerString(code int, msg string)
- func (c *Context) ServerXML(code int, data interface{})
- func (c *Context) ServerYAML(code int, data interface{})
- func (c *Context) SessionBool(key string) bool
- func (c *Context) SessionInt(key string) int
- func (c *Context) SessionInt64(key string) int64
- func (c *Context) SessionString(key string) string
- func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (c *Context) SetKey(key string, value interface{})
- func (c *Context) SetSameSite(samSite http.SameSite)
- func (c *Context) SetSession(key string, v interface{})
- func (c *Context) Status(code int)
- func (c *Context) StopRun()
- func (c *Context) String(msg string)
- func (c *Context) UserAgent() string
- func (c *Context) XML(data interface{})
- func (c *Context) YAML(data interface{})
- type DataResponse
- type Engine
- func (engine *Engine) AddFuncMap(key string, fn interface{})
- func (engine *Engine) Match(method, path string, match *matchValue) bool
- func (engine *Engine) NoRoute(handlers ...HandlerFunc)
- func (engine *Engine) PrintRouteMap()
- func (engine *Engine) ResetRoute()
- func (engine *Engine) RouteMap() []*RouteMapInfo
- func (engine *Engine) Run(args ...interface{}) (err error)
- func (engine *Engine) RunFd(fd int) (err error)
- func (engine *Engine) RunTLS(certFile, keyFile string, args ...interface{}) (err error)
- func (engine *Engine) RunTLSLoadConfig(cfg *tls.Config, args ...interface{}) (err error)
- func (engine *Engine) RunUnix(file string) (err error)
- func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (engine *Engine) SetAppConfig(app *AppConfig)
- func (engine *Engine) SetGzipOn(on bool)
- func (engine *Engine) SetIgnoreCase(ignore bool)
- func (engine *Engine) SetIgnoreTrailingSlash(ignore bool)
- func (engine *Engine) SetViews(path string)
- func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes
- type Error
- type ErrorType
- type ExcludedExtensions
- type ExcludedPathesRegexs
- type ExcludedPaths
- type H
- type HandlerFunc
- func CustomRecovery(handle RecoveryFunc) HandlerFunc
- func CustomRecoveryWithWriter(out io.Writer, handle RecoveryFunc) HandlerFunc
- func DataPager() HandlerFunc
- func Gzip(level int, options ...Option) HandlerFunc
- func Logger() HandlerFunc
- func Recovery() HandlerFunc
- func RecoveryWithWriter(out io.Writer, recovery ...RecoveryFunc) HandlerFunc
- func Session() HandlerFunc
- type HandlersChain
- type IRouter
- type IRoutes
- type LogFormatterParams
- type Option
- type Options
- type Pager
- type Param
- type Params
- type RecoveryFunc
- type ResponseWriter
- type Route
- type RouteMapInfo
- type RouterGroup
- func (group *RouterGroup) Any(path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) DELETE(path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) GET(path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) Group(path string, handlers ...HandlerFunc) *RouterGroup
- func (group *RouterGroup) HEAD(path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) Handle(method, path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) OPTIONS(path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) PATCH(path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) POST(path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) PUT(path string, handlers ...HandlerFunc) IRoutes
- func (group *RouterGroup) Static(path, root string) IRoutes
- func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes
- func (group *RouterGroup) StaticFile(path, filepath string) IRoutes
- func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes
Constants ¶
const ( ContentJSON = "application/json; charset=utf-8" ContentAsciiJSON = "application/json" ContentHTML = "text/html; charset=utf-8" ContentJavaScript = "application/javascript; charset=utf-8" ContentXML = "application/xml; charset=utf-8" ContentPlain = "text/plain; charset=utf-8" ContentYAML = "application/x-yaml; charset=utf-8" ContentDownload = "application/octet-stream; charset=utf-8" )
const ( DevMode = "dev" ProdMode = "prod" )
const ( BestCompression = gzip.BestCompression BestSpeed = gzip.BestSpeed DefaultCompression = gzip.DefaultCompression NoCompression = gzip.NoCompression )
Variables ¶
var ( DefaultExcludedExtentions = NewExcludedExtensions([]string{ ".png", ".gif", ".jpeg", ".jpg", }) DefaultOptions = &Options{ ExcludedExtensions: DefaultExcludedExtentions, } )
Functions ¶
func BytesToString ¶ added in v1.0.3
BytesToString converts byte slice to string without a memory allocation.
func DefaultDecompressHandle ¶
func DefaultDecompressHandle(c *Context)
DefaultDecompressHandle default handle
func Dir ¶
func Dir(root string, listDirectory bool) http.FileSystem
Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally in router.Static(). if listDirectory == true, then it works the same as http.Dir() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.
func InitSession ¶
func InitSession()
InitSession init gow session
before using session,please call this function first
func IsDebugging ¶
func IsDebugging() bool
func StringToBytes ¶ added in v1.0.3
StringToBytes converts string to byte slice without a memory allocation.
Types ¶
type AppConfig ¶
type AppConfig struct { AppName string `json:"app_name,omitempty" yaml:"app_name"` // app name RunMode string `json:"run_mode,omitempty" yaml:"run_mode"` // app run mode HTTPAddr string `json:"http_addr,omitempty" yaml:"http_addr"` // http address AutoRender bool `json:"auto_render,omitempty" yaml:"auto_render"` // if true load html template Views string `json:"views,omitempty" yaml:"views"` // html template dir TemplateLeft string `json:"template_left,omitempty" yaml:"template_left"` // html template tag symbol TemplateRight string `json:"template_right,omitempty" yaml:"template_right"` // html template tag symbol SessionOn bool `json:"session_on,omitempty" yaml:"session_on"` // if true open session GzipOn bool `json:"gzip_on,omitempty" yaml:"gzip_on"` // if true:load gzip middleware IgnoreCase bool `json:"ignore_case" yaml:"ignore_case"` // if true ignore case on route }
AppConfig unified configuration entry
type Body ¶
type Body struct { Pager *Pager `json:"pager"` Data interface{} `json:"data"` }
Body struct
type Context ¶
type Context struct { Request *http.Request Writer ResponseWriter Params Params Keys map[string]interface{} // Data html template render Data Data map[interface{}]interface{} Pager *Pager Errors errorMsgs // contains filtered or unexported fields }
Context gow context
func (*Context) AbortWithError ¶
AbortWithError abort and error
func (*Context) AbortWithStatus ¶
AbortWithStatus abort and write status code
func (*Context) AsciiJSON ¶ added in v1.0.3
func (c *Context) AsciiJSON(data interface{})
AsciiJSON response ascii JSON
func (*Context) DataJSON ¶
func (c *Context) DataJSON(args ...interface{})
DataJSON response JSON format
c.DataJSON(1,"lost param") c.DataJSON()
func (*Context) DecodeJSONBody ¶
DecodeJSONBody Unmarshal request body to v
user:=&User{} err:=c.DecodeJSONBody(&user)
func (*Context) DeleteSession ¶
DeleteSession delete session key
func (*Context) DownLoadFile ¶
DownLoadFile download data to filename
c.DownLoadFile(data,"table.xlsx")
func (*Context) FileAttachment ¶
FileAttachment writes the specified file into the body stream in an efficient way On the client side, the file will typically be downloaded with the given filename
func (*Context) GetFiles ¶
func (c *Context) GetFiles(key string) ([]*multipart.FileHeader, error)
GetFiles get files from request
func (*Context) GetFloat64 ¶
GetFloat64 return float64 and error
func (*Context) GetHeader ¶
GetHeader returns value from request headers.
userAgent:=c.GetHeader("user-agent)
func (*Context) GetSession ¶
GetSession return interface
func (*Context) GetString ¶
GetString return string
def: default value
request url: /article?id=111 id:=c.GetString("id")
func (*Context) GetStrings ¶
GetStrings return []string request url: /article?id=111&id=456 ids:=c.GetStrings("id")
func (*Context) HandlerNames ¶
HandlerNames return []string
func (*Context) IsWebsocket ¶
IsWebsocket return is websocket request
func (*Context) JSON ¶
func (c *Context) JSON(data interface{})
JSON response JSON data
user:=&User{} c.JSON(user)
func (*Context) KeyBool ¶ added in v1.0.6
KeyBool returns the value associated with the key as a boolean.
func (*Context) KeyDuration ¶ added in v1.0.6
KeyDuration returns the value associated with the key as a duration.
func (*Context) KeyFloat64 ¶ added in v1.0.6
KeyFloat64 returns the value associated with the key as a float64.
func (*Context) KeyInt ¶ added in v1.0.6
KeyInt returns the value associated with the key as an integer.
func (*Context) KeyInt64 ¶ added in v1.0.6
KeyInt64 returns the value associated with the key as an integer.
func (*Context) KeyString ¶ added in v1.0.6
KeyString returns the value associated with the key as a string.
func (*Context) KeyStringMap ¶ added in v1.0.6
KeyStringMap returns the value associated with the key as a map of interfaces.
func (*Context) KeyStringMapString ¶ added in v1.0.6
KeyStringMapString returns the value associated with the key as a map of strings.
func (*Context) KeyStringMapStringSlice ¶ added in v1.0.6
KeyStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
func (*Context) KeyStringSlice ¶ added in v1.0.6
KeyStringSlice returns the value associated with the key as a slice of strings.
func (*Context) KeyTime ¶ added in v1.0.6
KeyTime returns the value associated with the key as time.
func (*Context) KeyUint ¶ added in v1.0.6
KeyUint returns the value associated with the key as an unsigned integer.
func (*Context) KeyUint64 ¶ added in v1.0.6
KeyUint64 returns the value associated with the key as an unsigned integer.
func (*Context) Param ¶
Param return the value of the URL param.
request path: /article/{id} c.Param(id)
func (*Context) ParamInt ¶
ParamInt return the value of the URL param
request path: /article/{id} c.ParamInt(id)
func (*Context) ParamInt64 ¶
ParamInt64 return the value of the URL param
request path: /article/{id} c.ParamInt64(id)
func (*Context) PureJSON ¶ added in v1.0.3
func (c *Context) PureJSON(data interface{})
PureJSON response pure JSON
func (*Context) SaveToFile ¶
SaveToFile upload the file and save it on the server.
c.SaveToFile("file","./upload/1.jpg")
func (*Context) SecureJSON ¶ added in v1.0.3
func (c *Context) SecureJSON(data interface{})
SecureJSON response secure JSON
func (*Context) ServerAsciiJSON ¶ added in v1.0.3
ServerAsciiJSON response ascii JSON
func (*Context) ServerDataJSON ¶
ServerDataJSON response JSON format
statusCode httpStatusCode like: c.ServerDataJSON(401,1,"UnAuthorized")
func (*Context) ServerHTML ¶
ServerHTML html page render
c.ServerHTML(200,"index.html") c.ServerHTML(200,"admin/login.html") c.ServerHTML(404,"error.html")
func (*Context) ServerJSON ¶
ServerJSON response JSON data
c.ServerJSON(200,"success") c.ServerJSON(404,structData) c.ServerJSON(404,mapData)
func (*Context) ServerJSONP ¶ added in v0.1.2
ServerJSONP write data by jsonp format
user:=&User{} c.ServerJSONP(200,"callback",user)
func (*Context) ServerPureJSON ¶ added in v1.0.3
ServerPureJSON response pure JSON
func (*Context) ServerSecureJSON ¶ added in v1.0.3
ServerSecureJSON response secure JSON
func (*Context) ServerString ¶
ServerString response text message
c.ServerString(200,"success") c.ServerString(404,"page not found")
func (*Context) SessionString ¶
SessionString return string
func (*Context) SetCookie ¶
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
SetCookie set cookie
c.SetCookie("name","zituocn",360,"/","",false,true)
func (*Context) SetSameSite ¶ added in v1.0.3
SetSameSite set http.SamSite
func (*Context) SetSession ¶
SetSession set session
type DataResponse ¶
type DataResponse struct { Code int `json:"code"` Msg string `json:"msg"` Time int `json:"time"` Body *Body `json:"body"` }
DataResponse data struct
type Engine ¶
type Engine struct { AppName string RunMode string AutoRender bool FuncMap template.FuncMap Render render.Render RouterGroup HandleMethodNotAllowed bool MaxMultipartMemory int64 // contains filtered or unexported fields }
Engine gow Engine
func Default ¶
func Default() *Engine
Default returns an Engine instance with the Logger and Recovery middleware already attached.
r:=gow.Default() r.Run()
func New ¶
func New() *Engine
New returns a new blank Engine instance without any middleware attached.
gzipOn false sessionOn false ignoreCase true ignoreTrailingSlash true AutoRender false RunMode = "dev"
func (*Engine) AddFuncMap ¶ added in v0.1.1
AddFuncMap add fn func to template func map
r.AddFuncMap("datetime",fn())
func (*Engine) NoRoute ¶
func (engine *Engine) NoRoute(handlers ...HandlerFunc)
NoRoute set 404 handler
r.NoRoute(error404Handler)
func (*Engine) PrintRouteMap ¶ added in v1.0.5
func (engine *Engine) PrintRouteMap()
PrintRouteMap print route map
func (*Engine) ResetRoute ¶ added in v1.2.5
func (engine *Engine) ResetRoute()
ResetRoute clear engine's route
func (*Engine) RouteMap ¶ added in v1.0.5
func (engine *Engine) RouteMap() []*RouteMapInfo
RouteMap return gow route
func (*Engine) Run ¶
Run start http service default 127.0.0.1:8080
r.Run() r.Run(8080) r.Run(":8080) r.Run("127.0.0.1:8080)
func (*Engine) RunTLSLoadConfig ¶ added in v1.3.6
RunTLSLoadConfig use tls.Config{}
func (*Engine) ServeHTTP ¶
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface.
func (*Engine) SetAppConfig ¶
SetAppConfig set engine config
gow.SetAppConfig(gow.GetAppConfig()) OR: gow.SetAppConfig(func())
func (*Engine) SetIgnoreTrailingSlash ¶ added in v1.0.8
SetIgnoreTrailingSlash set ignore trailing slash one the route
r.SetIgnoreTrailingSlash(true)
func (*Engine) Use ¶
func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes
Use middleware
r.Use(Auth())
type Error ¶
func (*Error) MarshalJSON ¶
MarshalJSON implements the json.Marshaller interface.
type ExcludedExtensions ¶
ExcludedExtensions Using map for better lookup performance
func NewExcludedExtensions ¶
func NewExcludedExtensions(extensions []string) ExcludedExtensions
func (ExcludedExtensions) Contains ¶
func (e ExcludedExtensions) Contains(target string) bool
type ExcludedPathesRegexs ¶
func NewExcludedPathesRegexs ¶
func NewExcludedPathesRegexs(regexs []string) ExcludedPathesRegexs
func (ExcludedPathesRegexs) Contains ¶
func (e ExcludedPathesRegexs) Contains(requestURI string) bool
type ExcludedPaths ¶
type ExcludedPaths []string
func NewExcludedPaths ¶
func NewExcludedPaths(paths []string) ExcludedPaths
func (ExcludedPaths) Contains ¶
func (e ExcludedPaths) Contains(requestURI string) bool
type HandlerFunc ¶
type HandlerFunc func(ctx *Context)
HandlerFunc gow handler
func(ctx *Context)
func CustomRecovery ¶
func CustomRecovery(handle RecoveryFunc) HandlerFunc
CustomRecovery returns a middleware that recovers from any panics and calls the provided handle func to handle it.
func CustomRecoveryWithWriter ¶
func CustomRecoveryWithWriter(out io.Writer, handle RecoveryFunc) HandlerFunc
CustomRecoveryWithWriter returns a middleware for a given writer that recovers from any panics and calls the provided handle func to handle it.
func DataPager ¶
func DataPager() HandlerFunc
DataPager middleware
r.Use(gow.DataPager()) like : /v1/user/page?page=1&limit=20
func Logger ¶
func Logger() HandlerFunc
func Recovery ¶
func Recovery() HandlerFunc
Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.
func RecoveryWithWriter ¶
func RecoveryWithWriter(out io.Writer, recovery ...RecoveryFunc) HandlerFunc
RecoveryWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.
func Session ¶
func Session() HandlerFunc
Session session middleware
r := gow.Default() r.Use(gow.Session())
type IRouter ¶
type IRouter interface { IRoutes Group(string, ...HandlerFunc) *RouterGroup }
type IRoutes ¶
type IRoutes interface { Handle(string, string, ...HandlerFunc) IRoutes Any(string, ...HandlerFunc) IRoutes GET(string, ...HandlerFunc) IRoutes POST(string, ...HandlerFunc) IRoutes DELETE(string, ...HandlerFunc) IRoutes PATCH(string, ...HandlerFunc) IRoutes PUT(string, ...HandlerFunc) IRoutes OPTIONS(string, ...HandlerFunc) IRoutes HEAD(string, ...HandlerFunc) IRoutes StaticFile(string, string) IRoutes Static(string, string) IRoutes StaticFS(string, http.FileSystem) IRoutes }
IRoutes all router handler interface.
type LogFormatterParams ¶
type LogFormatterParams struct { Request *http.Request //AppName AppName string // TimeStamp shows the time after the server returns a response. TimeStamp time.Time // StatusCode is HTTP response code. StatusCode int // Latency is how much time the server cost to process a certain request. Latency time.Duration // ClientIP equals Context's ClientIP method. ClientIP string // Method is the HTTP method given to the request. Method string // Path is a path the client requests. Path string // ErrorMessage is set if error has occurred in processing the request. ErrorMessage string // BodySize is the size of the Response Body BodySize int // Keys are the keys set on the request's context. Keys map[string]interface{} // contains filtered or unexported fields }
func (*LogFormatterParams) IsOutputColor ¶
func (p *LogFormatterParams) IsOutputColor() bool
IsOutputColor indicates whether can colors be outputted to the logx.
func (*LogFormatterParams) MethodColor ¶
func (p *LogFormatterParams) MethodColor() string
MethodColor is the ANSI color for appropriately logging http method to a terminal.
func (*LogFormatterParams) ResetColor ¶
func (p *LogFormatterParams) ResetColor() string
ResetColor resets all escape attributes.
func (*LogFormatterParams) StatusCodeColor ¶
func (p *LogFormatterParams) StatusCodeColor() string
StatusCodeColor is the ANSI color for appropriately logging http status code to a terminal.
type Option ¶
type Option func(*Options)
func WithDecompressFn ¶
func WithExcludedExtensions ¶
func WithExcludedPaths ¶
func WithExcludedPathsRegexs ¶
type Options ¶
type Options struct { ExcludedExtensions ExcludedExtensions ExcludedPaths ExcludedPaths ExcludedPathesRegexs ExcludedPathesRegexs DecompressFn func(c *Context) }
type Pager ¶
type Pager struct { Page int64 `json:"page"` Limit int64 `json:"-"` Offset int64 `json:"-"` Count int64 `json:"count"` PageCount int64 `json:"page_count"` }
Pager pager struct
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type RecoveryFunc ¶
type RecoveryFunc func(c *Context, err interface{})
RecoveryFunc defines the function passable to CustomRecovery.
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.Flusher http.CloseNotifier // Status Returns the HTTP response status code of the current request. Status() int // Size Returns the number of bytes already written into the response http body. // See Written() Size() int // WriteString Writes the string into the response body. WriteString(string) (int, error) // Written Returns true if the response body was already written. Written() bool // WriteHeaderNow Forces to write the http header (status code + headers). WriteHeaderNow() // Pusher get the http.Pusher for server push Pusher() http.Pusher }
ResponseWriter interface
type RouteMapInfo ¶ added in v1.0.5
type RouteMapInfo struct { Method string Path string Handler string Handlers HandlersChain }
RouteMapInfo route map info
type RouterGroup ¶
type RouterGroup struct { Handlers HandlersChain // contains filtered or unexported fields }
RouterGroup is used internally to configure router.
func (*RouterGroup) Any ¶
func (group *RouterGroup) Any(path string, handlers ...HandlerFunc) IRoutes
Any register all HTTP methods.
r.Aay("/",handler) r.Aay("/article/{id}.html",handler)
func (*RouterGroup) DELETE ¶
func (group *RouterGroup) DELETE(path string, handlers ...HandlerFunc) IRoutes
DELETE register DELETE handler
r.DELETE("/",handler) r.DELETE("/article/{id}",handler)
func (*RouterGroup) GET ¶
func (group *RouterGroup) GET(path string, handlers ...HandlerFunc) IRoutes
GET register GET handler
r.GET("/",handler) r.GET("/article/{id}.html",handler)
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(path string, handlers ...HandlerFunc) *RouterGroup
Group create a new route group.
v1:=r.Group("/v1") THEN: v1.GET("/user",...)
func (*RouterGroup) HEAD ¶
func (group *RouterGroup) HEAD(path string, handlers ...HandlerFunc) IRoutes
HEAD register HEAD handler
r.HEAD("/",handler) r.HEAD("/article/{id}",handler)
func (*RouterGroup) Handle ¶
func (group *RouterGroup) Handle(method, path string, handlers ...HandlerFunc) IRoutes
Handle registers a new request handle and middleware with the given path and method
r.Handle("GET","/",handler) r.Handle("GET,POST","/",handler) r.Handle("GET,POST,PUT,DELETE","/article/{id}",handler)
func (*RouterGroup) OPTIONS ¶
func (group *RouterGroup) OPTIONS(path string, handlers ...HandlerFunc) IRoutes
OPTIONS register OPTIONS handler
r.OPTIONS("/",handler) r.OPTIONS("/article/{id}",handler)
func (*RouterGroup) PATCH ¶
func (group *RouterGroup) PATCH(path string, handlers ...HandlerFunc) IRoutes
PATCH register PATCH handler
func (*RouterGroup) POST ¶
func (group *RouterGroup) POST(path string, handlers ...HandlerFunc) IRoutes
POST register POST handler
r.POST("/",handler) r.POST("/article/{id}.html",handler)
func (*RouterGroup) PUT ¶
func (group *RouterGroup) PUT(path string, handlers ...HandlerFunc) IRoutes
PUT register PUT handler
func (*RouterGroup) Static ¶
func (group *RouterGroup) Static(path, root string) IRoutes
Static handler static dir
r.Static("/static","static")
func (*RouterGroup) StaticFS ¶
func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes
StaticFS r.StaticFS(path,fs)
func (*RouterGroup) StaticFile ¶
func (group *RouterGroup) StaticFile(path, filepath string) IRoutes
StaticFile static file
r.StaticFile("/favicon.png","/static/img/favicon.png")
func (*RouterGroup) Use ¶
func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes
Use add middleware to the group
func Demo() gow.HandlerFunc{ return func(c *Context) { TODO: c.Next() } }
r.Use(Demo()) OR: r.Use(Demo(),Demo2())