Documentation ¶
Index ¶
- Constants
- Variables
- func IsZeroTime(t time.Time) bool
- type App
- func (app *App) ANY(url string, handler ...Handler) *App
- func (app *App) AppendReqAndResp(url, method string, handler []Handler)
- func (app *App) DELETE(url string, handler ...Handler) *App
- func (app *App) Find(url, method string) []Handler
- func (app *App) GET(url string, handler ...Handler) *App
- func (app *App) Group(prefix string, middleware ...Handler) *RouterGroup
- func (app *App) HEAD(url string, handler ...Handler) *App
- func (app *App) Name(name string)
- func (app *App) OPTIONS(url string, handler ...Handler) *App
- func (app *App) POST(url string, handler ...Handler) *App
- func (app *App) PUT(url string, handler ...Handler) *App
- type Context
- func (ctx *Context) Abort()
- func (ctx *Context) AddHeader(key, value string)
- func (ctx *Context) BindJSON(data interface{}) error
- func (ctx *Context) CheckIfModifiedSince(modtime time.Time) (bool, error)
- func (ctx *Context) Cookie(name string) string
- func (ctx *Context) Data(code int, contentType string, data []byte)
- func (ctx *Context) DataWithHeaders(code int, header map[string]string, data []byte)
- func (ctx *Context) FormValue(key string) string
- func (ctx *Context) GetContentType() string
- func (ctx *Context) HTML(code int, body string)
- func (ctx *Context) HTMLByte(code int, body []byte)
- func (ctx *Context) Headers(key string) string
- func (ctx *Context) IsPjax() bool
- func (ctx *Context) JSON(code int, Body map[string]interface{})
- func (ctx *Context) Lang() string
- func (ctx *Context) LocalIP() string
- func (ctx *Context) Method() string
- func (ctx *Context) MustBindJSON(data interface{})
- func (ctx *Context) Next()
- func (ctx *Context) Path() string
- func (ctx *Context) PjaxUrl(url string)
- func (ctx *Context) PostForm() url.Values
- func (ctx *Context) Query(key string) string
- func (ctx *Context) QueryAll(key string) []string
- func (ctx *Context) QueryDefault(key, def string) string
- func (ctx *Context) Redirect(path string)
- func (ctx *Context) Referer() string
- func (ctx *Context) RefererQuery(key string) string
- func (ctx *Context) RefererURL() *url.URL
- func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time, ...) error
- func (ctx *Context) ServeFile(filename string, gzipCompression bool) error
- func (ctx *Context) SetContentType(contentType string)
- func (ctx *Context) SetCookie(cookie *http.Cookie)
- func (ctx *Context) SetHandlers(handlers Handlers) *Context
- func (ctx *Context) SetHeader(key, value string)
- func (ctx *Context) SetLastModified(modtime time.Time)
- func (ctx *Context) SetStatusCode(code int)
- func (ctx *Context) SetUserValue(key string, value interface{})
- func (ctx *Context) User() interface{}
- func (ctx *Context) WantHTML() bool
- func (ctx *Context) WantJSON() bool
- func (ctx *Context) Write(code int, header map[string]string, Body string)
- func (ctx *Context) WriteNotModified()
- func (ctx *Context) WriteString(body string)
- type Handler
- type HandlerMap
- type Handlers
- type Node
- type NodeProcessor
- type Path
- type Router
- type RouterGroup
- func (g *RouterGroup) ANY(url string, handler ...Handler) *RouterGroup
- func (g *RouterGroup) AppendReqAndResp(url, method string, handler []Handler)
- func (g *RouterGroup) DELETE(url string, handler ...Handler) *RouterGroup
- func (g *RouterGroup) GET(url string, handler ...Handler) *RouterGroup
- func (g *RouterGroup) Group(prefix string, middleware ...Handler) *RouterGroup
- func (g *RouterGroup) HEAD(url string, handler ...Handler) *RouterGroup
- func (g *RouterGroup) Name(name string)
- func (g *RouterGroup) OPTIONS(url string, handler ...Handler) *RouterGroup
- func (g *RouterGroup) POST(url string, handler ...Handler) *RouterGroup
- func (g *RouterGroup) PUT(url string, handler ...Handler) *RouterGroup
- type RouterMap
Constants ¶
const ( HeaderContentType = "Content-Type" HeaderLastModified = "Last-Modified" HeaderIfModifiedSince = "If-Modified-Since" HeaderCacheControl = "Cache-Control" HeaderETag = "ETag" HeaderContentDisposition = "Content-Disposition" HeaderContentLength = "Content-Length" HeaderContentEncoding = "Content-Encoding" GzipHeaderValue = "gzip" HeaderAcceptEncoding = "Accept-Encoding" HeaderVary = "Vary" )
Variables ¶
var ParseTime = func(text string) (t time.Time, err error) { t, err = time.Parse(http.TimeFormat, text) if err != nil { return http.ParseTime(text) } return }
ParseTime parses a time header (such as the Date: header), trying each forth formats that are allowed by HTTP/1.1: time.RFC850, and time.ANSIC.
Functions ¶
func IsZeroTime ¶
IsZeroTime reports whether t is obviously unspecified (either zero or Unix()=0).
Types ¶
type App ¶
type App struct { Requests []Path Handlers HandlerMap Middlewares Handlers Prefix string Routers RouterMap // contains filtered or unexported fields }
App is the key struct of the package. App as a member of plugin entity contains the request and the corresponding handler. Prefix is the url prefix and MiddlewareList is for control flow.
func (*App) ANY ¶
ANY registers a route that matches all the HTTP methods. GET, POST, PUT, HEAD, OPTIONS, DELETE.
func (*App) AppendReqAndResp ¶
AppendReqAndResp stores the request info and handle into app. support the route parameter. The route parameter will be recognized as wildcard store into the RegUrl of Path struct. For example:
/user/:id => /user/(.*) /user/:id/info => /user/(.*?)/info
The RegUrl will be used to recognize the incoming path and find the handler.
func (*App) Group ¶
func (app *App) Group(prefix string, middleware ...Handler) *RouterGroup
Group add middlewares and prefix for App.
type Context ¶
type Context struct { Request *http.Request Response *http.Response UserValue map[string]interface{} // contains filtered or unexported fields }
Context is the simplify version of web framework context. But it is important which will be used in plugins to custom the request and response. And adapter will help to transform the Context to the web framework`s context. It has three attributes. Request and response are belongs to net/http package. UserValue is the custom key-value store of context.
func NewContext ¶
NewContext used in adapter which return a Context with request and slice of UserValue and a default Response.
func (*Context) CheckIfModifiedSince ¶
func (*Context) DataWithHeaders ¶
DataWithHeaders save the given status code, headers and body data into the response.
func (*Context) GetContentType ¶
func (*Context) JSON ¶
JSON serializes the given struct as JSON into the response body. It also sets the Content-Type as "application/json".
func (*Context) MustBindJSON ¶
func (ctx *Context) MustBindJSON(data interface{})
func (*Context) QueryDefault ¶
QueryDefault get the query parameter of url. If it is empty, return the default.
func (*Context) RefererQuery ¶
RefererQuery retrieve the value of given key from url.URL object of request header Referer.
func (*Context) RefererURL ¶
RefererURL get the url.URL object of request header Referer.
func (*Context) ServeContent ¶
func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time, gzipCompression bool) error
ServeContent serves content, headers are autoset receives three parameters, it's low-level function, instead you can use .ServeFile(string,bool)/SendFile(string,string)
You can define your own "Content-Type" header also, after this function call Doesn't implements resuming (by range), use ctx.SendFile instead
func (*Context) ServeFile ¶
ServeFile serves a view file, to send a file ( zip for example) to the client you should use the SendFile(serverfilename,clientfilename)
func (*Context) SetContentType ¶
SetContentType save the given content type header into the response header.
func (*Context) SetCookie ¶
SetCookie save the given cookie obj into the response Set-Cookie header.
func (*Context) SetHandlers ¶
SetHandlers set the handlers of Context.
func (*Context) SetLastModified ¶
func (*Context) SetStatusCode ¶
SetStatusCode save the given status code into the response.
func (*Context) SetUserValue ¶
SetUserValue set the value of user context.
func (*Context) Write ¶
Write save the given status code, headers and body string into the response.
func (*Context) WriteNotModified ¶
func (ctx *Context) WriteNotModified()
func (*Context) WriteString ¶
WriteString save the given body string into the response.
type Handler ¶
type Handler func(ctx *Context)
Handler defines the handler used by the middleware as return value.
type HandlerMap ¶
type NodeProcessor ¶
type NodeProcessor func(...Node)
type Path ¶
Path is used in the matching of request and response. Url stores the raw register url. RegUrl contains the wildcard which on behalf of the route params.
type RouterGroup ¶
type RouterGroup struct { Middlewares Handlers Prefix string // contains filtered or unexported fields }
RouterGroup is a group of routes.
func (*RouterGroup) ANY ¶
func (g *RouterGroup) ANY(url string, handler ...Handler) *RouterGroup
ANY registers a route that matches all the HTTP methods. GET, POST, PUT, HEAD, OPTIONS, DELETE.
func (*RouterGroup) AppendReqAndResp ¶
func (g *RouterGroup) AppendReqAndResp(url, method string, handler []Handler)
AppendReqAndResp stores the request info and handle into app. support the route parameter. The route parameter will be recognized as wildcard store into the RegUrl of Path struct. For example:
/user/:id => /user/(.*) /user/:id/info => /user/(.*?)/info
The RegUrl will be used to recognize the incoming path and find the handler.
func (*RouterGroup) DELETE ¶
func (g *RouterGroup) DELETE(url string, handler ...Handler) *RouterGroup
DELETE is a shortcut for app.AppendReqAndResp(url, "delete", handler).
func (*RouterGroup) GET ¶
func (g *RouterGroup) GET(url string, handler ...Handler) *RouterGroup
GET is a shortcut for app.AppendReqAndResp(url, "get", handler).
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(prefix string, middleware ...Handler) *RouterGroup
Group add middlewares and prefix for RouterGroup.
func (*RouterGroup) HEAD ¶
func (g *RouterGroup) HEAD(url string, handler ...Handler) *RouterGroup
HEAD is a shortcut for app.AppendReqAndResp(url, "head", handler).
func (*RouterGroup) Name ¶
func (g *RouterGroup) Name(name string)
func (*RouterGroup) OPTIONS ¶
func (g *RouterGroup) OPTIONS(url string, handler ...Handler) *RouterGroup
OPTIONS is a shortcut for app.AppendReqAndResp(url, "options", handler).
func (*RouterGroup) POST ¶
func (g *RouterGroup) POST(url string, handler ...Handler) *RouterGroup
POST is a shortcut for app.AppendReqAndResp(url, "post", handler).
func (*RouterGroup) PUT ¶
func (g *RouterGroup) PUT(url string, handler ...Handler) *RouterGroup
PUT is a shortcut for app.AppendReqAndResp(url, "put", handler).