Documentation ¶
Index ¶
- Variables
- func DefaultGroup(prefix string, fn func(r *RouterGroup))
- func DefaultMiddleware(name string, fn func(app *Application))
- type Application
- type Cache
- type Context
- func (ctx *Context) AcceptJSON() bool
- func (ctx *Context) AddHeader(key string, value string)
- func (ctx *Context) BasicAuth() (string, string, bool)
- func (ctx *Context) BindForm(obj interface{}) error
- func (ctx *Context) BindHeader(obj interface{}) error
- func (ctx *Context) BindJSON(obj interface{}) error
- func (ctx *Context) BindParams(obj interface{}) error
- func (ctx *Context) BindQuery(obj interface{}) error
- func (ctx *Context) BindYAML(obj interface{}) error
- func (ctx *Context) Bodies() map[string]any
- func (ctx *Context) Cookies() map[string]string
- func (ctx *Context) Error(status int, message string)
- func (ctx *Context) Fail(code int, message string)
- func (ctx *Context) File(key string) multipart.File
- func (ctx *Context) Files() map[string]*multipart.FileHeader
- func (ctx *Context) Form(key string, defaultValue ...string) string
- func (ctx *Context) Forms() *safe.Map
- func (ctx *Context) Get(key string) string
- func (ctx *Context) HTML(code int, name string, data interface{})
- func (ctx *Context) Header(key string) string
- func (ctx *Context) Headers() *safe.Map
- func (ctx *Context) Host() string
- func (ctx *Context) IP() string
- func (ctx *Context) JSON(status int, obj interface{})
- func (ctx *Context) Next()
- func (ctx *Context) Origin() string
- func (ctx *Context) Param(key string, defaultValue ...string) string
- func (ctx *Context) Params() *safe.Map
- func (ctx *Context) Queries() *safe.Map
- func (ctx *Context) Query(key string, defaultValue ...string) string
- func (ctx *Context) Redirect(url string, status ...int)
- func (ctx *Context) Render(code int, name string, data interface{})
- func (ctx *Context) SaveFile(key, path string) error
- func (ctx *Context) Set(key string, value string)
- func (ctx *Context) SetHeader(key string, value string)
- func (ctx *Context) Status(status int)
- func (ctx *Context) Stream() io.ReadCloser
- func (ctx *Context) String(status int, format string, values ...interface{})
- func (ctx *Context) Success(result interface{})
- func (ctx *Context) URL() string
- func (ctx *Context) Write(b []byte)
- type Cookie
- type Env
- type H
- type HandlerFunc
- type Middleware
- type ResponseWriter
- type RouterGroup
- func (g *RouterGroup) Any(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Delete(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Get(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Group(prefix string) *RouterGroup
- func (g *RouterGroup) Head(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Options(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Patch(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Post(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Put(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Static(relativePath string, root string, options ...StaticOptions)
- func (g *RouterGroup) StaticFS(relativePath string, fs http.FileSystem)
- func (g *RouterGroup) Use(middlewares ...HandlerFunc)
- func (g *RouterGroup) WebSocket(path string, handler WsHandlerFunc) *RouterGroup
- type Session
- type StaticOptions
- type WebSocketClient
- type WsHandlerFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultGroupsFns = map[string]func(r *RouterGroup){}
DefaultGroupsFns ...
var DefaultMiddlewares = map[string]func(app *Application){}
DefaultMiddlewares is the default global middleware
var Version = "1.0.31"
Version is the current version of the package.
Functions ¶
func DefaultGroup ¶ added in v1.0.16
func DefaultGroup(prefix string, fn func(r *RouterGroup))
DefaultGroup ...
func DefaultMiddleware ¶ added in v1.0.16
func DefaultMiddleware(name string, fn func(app *Application))
DefaultMiddleware ...
Types ¶
type Application ¶
type Application struct { *RouterGroup // SecretKey string LogLevel string // CacheConfig *typing.Config Cache *Cache // Env *Env Logger *logger.Logger // contains filtered or unexported fields }
Application is the handler for all requests.
func (*Application) Fallback ¶
func (app *Application) Fallback(h HandlerFunc)
Fallback is the default handler for all requests.
func (*Application) NotFound ¶
func (app *Application) NotFound(h HandlerFunc)
NotFound defines the 404 handler, replaced of built in not found handler.
func (*Application) Run ¶
func (app *Application) Run(addr ...string)
Run defines the method to start the server
func (*Application) ServeHTTP ¶
func (app *Application) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*Application) SetTemplates ¶
func (app *Application) SetTemplates(dir string, fns ...template.FuncMap)
SetTemplates set the template
type Cache ¶ added in v1.0.24
type Cache struct {
// contains filtered or unexported fields
}
Cache ...
type Context ¶
type Context struct { // origin objects Writer ResponseWriter Request *http.Request // request Method string Path string // response StatusCode int // Cookie *Cookie // Session *Session // Cache *Cache // App *Application // State map[string]interface{} // Env *Env // Logger *logger.Logger // contains filtered or unexported fields }
Context is the request context
func (*Context) AcceptJSON ¶ added in v1.0.19
AcceptJSON returns true if the request accepts json.
func (*Context) BasicAuth ¶ added in v1.0.1
BasicAuth returns the user/password pair for Basic Authentication.
func (*Context) BindHeader ¶ added in v1.0.1
BindHeader binds the header into the given struct.
func (*Context) BindParams ¶ added in v1.0.1
BindParams binds the params into the given struct.
func (*Context) Fail ¶
Fail writes the given error with code-message-result specification to the response.
func (*Context) Files ¶ added in v1.0.1
func (ctx *Context) Files() map[string]*multipart.FileHeader
Files gets all files.
func (*Context) IP ¶ added in v1.0.4
IP gets the ip from X-Forwarded-For or X-Real-IP or RemoteAddr.
func (*Context) Next ¶
func (ctx *Context) Next()
Next runs the next handler in the middleware stack
func (*Context) Stream ¶ added in v1.0.1
func (ctx *Context) Stream() io.ReadCloser
Stream get the body stream.
func (*Context) Success ¶
func (ctx *Context) Success(result interface{})
Success writes the given data with code-message-result specification to the response.
type Cookie ¶ added in v1.0.5
type Cookie struct {
// contains filtered or unexported fields
}
Cookie is a middleware for handling cookie.
type HandlerFunc ¶
type HandlerFunc func(ctx *Context)
HandlerFunc defines the request handler used by gee
func NotFound ¶
func NotFound() HandlerFunc
NotFound returns a HandlerFunc that replies with a 404 not found
func WrapH ¶
func WrapH(handler http.Handler) HandlerFunc
WrapH wraps a http.Handler to a HandlerFunc
type Middleware ¶ added in v1.0.20
type Middleware = HandlerFunc
Middleware defines the signature of the middleware function.
type ResponseWriter ¶ added in v1.0.12
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.CloseNotifier http.Flusher Status() int Size() int // WriteString writes the string into the response body. WriteString(string) (int, error) Written() bool // contains filtered or unexported methods }
ResponseWriter ...
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup is a group of routes.
func (*RouterGroup) Any ¶ added in v1.0.3
func (g *RouterGroup) Any(path string, handler ...HandlerFunc) *RouterGroup
Any defines all request methods (anyMethods)
func (*RouterGroup) Delete ¶
func (g *RouterGroup) Delete(path string, handler ...HandlerFunc) *RouterGroup
Delete defines the method to add DELETE request
func (*RouterGroup) Get ¶
func (g *RouterGroup) Get(path string, handler ...HandlerFunc) *RouterGroup
Get defines the method to add GET request
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(prefix string) *RouterGroup
Group defines a new router group
func (*RouterGroup) Head ¶
func (g *RouterGroup) Head(path string, handler ...HandlerFunc) *RouterGroup
Head defines the method to add HEAD request
func (*RouterGroup) Options ¶ added in v1.0.3
func (g *RouterGroup) Options(path string, handler ...HandlerFunc) *RouterGroup
Options defines the method to add OPTIONS request
func (*RouterGroup) Patch ¶
func (g *RouterGroup) Patch(path string, handler ...HandlerFunc) *RouterGroup
Patch defines the method to add PATCH request
func (*RouterGroup) Post ¶
func (g *RouterGroup) Post(path string, handler ...HandlerFunc) *RouterGroup
Post defines the method to add POST request
func (*RouterGroup) Put ¶
func (g *RouterGroup) Put(path string, handler ...HandlerFunc) *RouterGroup
Put defines the method to add PUT request
func (*RouterGroup) Static ¶
func (g *RouterGroup) Static(relativePath string, root string, options ...StaticOptions)
Static defines the method to serve static files
func (*RouterGroup) StaticFS ¶ added in v1.0.15
func (g *RouterGroup) StaticFS(relativePath string, fs http.FileSystem)
StaticFS defines the method to serve static files
func (*RouterGroup) Use ¶
func (g *RouterGroup) Use(middlewares ...HandlerFunc)
Use adds a middleware to the group
func (*RouterGroup) WebSocket ¶ added in v1.0.28
func (g *RouterGroup) WebSocket(path string, handler WsHandlerFunc) *RouterGroup
WebSocket defines the method to add websocket route
type Session ¶ added in v1.0.14
type Session struct {
// contains filtered or unexported fields
}
Session is the http session based on cookie.
type StaticOptions ¶
type StaticOptions struct { Gzip bool Md5 bool CacheControl string MaxAge time.Duration Index bool Suffix string }
StaticOptions is the options for static method
type WebSocketClient ¶ added in v1.0.28
type WebSocketClient struct { OnConnect func() OnDisconnect func() OnMessage func(typ int, msg []byte) OnTextMessage func(msg []byte) OnBinaryMessage func(msg []byte) OnError func(err error) // contains filtered or unexported fields }
WebSocketClient ...
func (*WebSocketClient) Disconnect ¶ added in v1.0.28
func (c *WebSocketClient) Disconnect()
Disconnect ...
func (*WebSocketClient) Write ¶ added in v1.0.28
func (c *WebSocketClient) Write(typ int, msg []byte) error
Write ...
func (*WebSocketClient) WriteBinary ¶ added in v1.0.28
func (c *WebSocketClient) WriteBinary(msg []byte) error
WriteBinary ...
func (*WebSocketClient) WriteJSON ¶ added in v1.0.28
func (c *WebSocketClient) WriteJSON(msg interface{}) error
WriteJSON ...
func (*WebSocketClient) WriteText ¶ added in v1.0.28
func (c *WebSocketClient) WriteText(msg string) error
WriteText ...
type WsHandlerFunc ¶ added in v1.0.28
type WsHandlerFunc func(ctx *Context, client *WebSocketClient)
WsHandlerFunc defines the websocket handler used by gee