Documentation ¶
Index ¶
- Constants
- func FileExists(filePath string) bool
- func HandleServeFileFallback(basePath string, fallbackFilePath string) func(c *C)
- func Stack() []byte
- type Ace
- type C
- func (c *C) Abort()
- func (c *C) AbortWithStatus(status int)
- func (c *C) AddHeader(key string, value string)
- func (c *C) ClientIP() string
- func (c *C) ClientRemoteAddress() string
- func (c *C) Download(status int, filename string, v []byte)
- func (c *C) DownloadStream(status int, filename string, v io.Reader)
- func (c *C) File(status int, filePath string)
- func (c *C) FormData() (url.Values, error)
- func (c *C) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (c *C) Get(key string) interface{}
- func (c *C) GetAll() map[string]interface{}
- func (c *C) JSON(status int, v interface{})
- func (c *C) MultipartFormData() (*multipart.Form, error)
- func (c *C) Next()
- func (c *C) Param(name string) string
- func (c *C) ParseJSON(v interface{}) error
- func (c *C) QueryString(key, d string) string
- func (c *C) QueryStringArray(key string, d []string) []string
- func (c *C) QueryStringInteger(key string, d int64) int64
- func (c *C) Sessions(name string) *sessions.Session
- func (c *C) Set(key string, v interface{})
- func (c *C) SetAll(data map[string]interface{})
- func (c *C) SetHeader(key string, value string)
- func (c *C) String(status int, format string, val ...interface{})
- type Context
- type HandlerFunc
- type PanicHandler
- type Renderer
- type ResponseWriter
- type Router
- func (r *Router) DELETE(path string, handlers ...HandlerFunc)
- func (r *Router) GET(path string, handlers ...HandlerFunc)
- func (r *Router) Group(path string, handlers ...HandlerFunc) *Router
- func (r *Router) HEAD(path string, handlers ...HandlerFunc)
- func (r *Router) Handle(method, path string, handlers []HandlerFunc)
- func (r *Router) HandlerFunc(h http.HandlerFunc) HandlerFunc
- func (r *Router) OPTIONS(path string, handlers ...HandlerFunc)
- func (r *Router) PATCH(path string, handlers ...HandlerFunc)
- func (r *Router) POST(path string, handlers ...HandlerFunc)
- func (r *Router) PUT(path string, handlers ...HandlerFunc)
- func (r *Router) Panic(h PanicHandler)
- func (r *Router) RouteNotFound(h HandlerFunc)
- func (r *Router) Static(path string, root http.Dir, handlers ...HandlerFunc)
- func (r *Router) Use(middlewares ...HandlerFunc)
- type SessionOptions
Constants ¶
const ( // 2xx status codes StatusOK = 200 StatusCreated = 201 StatusAccepted = 202 // 4xx status codes StatusBadRequest = 400 StatusPaymentRequired = 402 StatusForbidden = 403 StatusNotFound = 404 StatusMethodNotAllowed = 405 StatusNotAcceptable = 406 StatusProxyAuthenticationRequired = 407 StatusRequestTimeout = 408 StatusConflict = 409 StatusGone = 410 StatusLengthRequired = 411 StatusPreconditionFailed = 412 StatusRequestEntityTooLarge = 413 StatusURITooLong = 414 StatusUnsupportedMediaType = 415 StatusRangeNotSatisfiable = 416 StatusExpectationFailed = 417 StatusImATeapot = 418 StatusUnprocessableEntity = 422 StatusLocked = 423 // 5xx status codes StatusInternalServerError = 500 StatusNotImplemented = 501 StatusBadGateway = 502 StatusGatewayTimeout = 504 HeaderAuthorization = "Authorization" HeaderContentType = "Content-Type" HeaderContentDisposition = "Content-Disposition" AbortMiddlewareIndex = math.MaxInt8 / 2 )
Variables ¶
This section is empty.
Functions ¶
func FileExists ¶
File exists returns whether or not the filePath exists and is a file
func HandleServeFileFallback ¶
HandleServeFileFallback is a helper method that generates a HTTP handler func. The handler will try to serve the requested URL, starting from basePath, and will otherwise serve the file located at fallbackFilePath if the requested file wasn't found in the first place. This effectively acts like nginx try_files, or Apache's RewriteCond XX -f.
Types ¶
type Ace ¶
type Ace struct { *Router // contains filtered or unexported fields }
func Default ¶
func Default() *Ace
Default server with recovery and logger middleware. Used for Unit Testing.
func (*Ace) HtmlTemplate ¶
HtmlTemplate sets the renderer to use for HTML templates
func (*Ace) ServeHTTP ¶
func (a *Ace) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP serves a request locally as if it was handled by the HTTP ace
func (*Ace) SetPoolSize ¶
SetPoolSize defines the number of write buffers we should keep
type C ¶
type C struct { Request *http.Request Writer ResponseWriter // contains filtered or unexported fields }
func (*C) AbortWithStatus ¶
AbortWithStatus stops the middleware chain and return the specified HTTP status code
func (*C) ClientIP ¶
ClientIP returns the remote IP address, without port. See ClientRemoteAddress for source IP and port.
func (*C) ClientRemoteAddress ¶
ClientRemoteAddress returns the remote IP address and port
func (*C) DownloadStream ¶
DownloadStream response with application/octet-stream, but reading from a io.Reader
func (*C) GetAll ¶
GetAll returns all the data previously stored in this context using C.Set() or C.SetAll().
func (*C) Next ¶
func (c *C) Next()
Next runs the next HandlerFunc in the stack (ie. the next middleware)
func (*C) QueryString ¶
QueryString returns a param value from the URL GET parameters, where "key" is the parameter key, and "d" is the default value when the key isn't set in the current request.
func (*C) QueryStringArray ¶
QueryString returns a param array from the URL GET parameters, where "key" is the parameter key, and "d" is the default value when the key isn't set in the current request.
func (*C) QueryStringInteger ¶
QueryStringInteger returns a param value from the URL GET parameters, where "key" is the parameter key, and "d" is the default value when the key isn't set in the current request, or if the value is not a valid integer..
type HandlerFunc ¶
type HandlerFunc func(c *C)
func Session ¶
func Session(store sessions.Store, options *SessionOptions) HandlerFunc
Session is the caller method that returns a Session middleware HandlerFunc
type PanicHandler ¶
type PanicHandler func(c *C, rcv interface{})
type Renderer ¶
type Renderer interface {
Render(w http.ResponseWriter, name string, data interface{})
}
Renderer is the interface that lets you use any HTML renderer
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Flusher // Status returns the status code of the response or 0 if the response has not been written. Status() int // Written returns whether or not the ResponseWriter has been written. Written() bool // Size returns the size of the response body. Size() int // Before allows for a function to be called before the ResponseWriter has been written to. This is // useful for setting headers or any other operations that must happen before a response has been written. Before(func(ResponseWriter)) }
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router http router
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handlers ...HandlerFunc)
DELETE handle DELETE method
func (*Router) GET ¶
func (r *Router) GET(path string, handlers ...HandlerFunc)
GET handle GET method
func (*Router) Group ¶
func (r *Router) Group(path string, handlers ...HandlerFunc) *Router
Group groups routes together onto a same path prefix
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, handlers ...HandlerFunc)
HEAD handle HEAD method
func (*Router) Handle ¶
func (r *Router) Handle(method, path string, handlers []HandlerFunc)
Handle handle with specific method
func (*Router) HandlerFunc ¶
func (r *Router) HandlerFunc(h http.HandlerFunc) HandlerFunc
HandlerFunc converts http.HandlerFunc to our own HandlerFunc
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handlers ...HandlerFunc)
OPTIONS handle OPTIONS method
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handlers ...HandlerFunc)
PATCH handle PATCH method
func (*Router) POST ¶
func (r *Router) POST(path string, handlers ...HandlerFunc)
POST handle POST method
func (*Router) PUT ¶
func (r *Router) PUT(path string, handlers ...HandlerFunc)
PUT handle PUT method
func (*Router) Panic ¶
func (r *Router) Panic(h PanicHandler)
Panic is the handler called when the panic() function is called
func (*Router) RouteNotFound ¶
func (r *Router) RouteNotFound(h HandlerFunc)
RouteNotFound is called call when no route match
type SessionOptions ¶
type SessionOptions struct { Path string Domain string // MaxAge=0 means no 'Max-Age' attribute specified. // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. // MaxAge>0 means Max-Age attribute present and given in seconds. MaxAge int Secure bool HTTPOnly bool }
SessionOptions are the options of the browser session
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
package pool is originally from github.com/plimble/utils/pool
|
package pool is originally from github.com/plimble/utils/pool |