Documentation ¶
Index ¶
- Constants
- Variables
- func GetPool() *pool.BufferPool
- func IsDebugging() bool
- func Stack() []byte
- type App
- func (l *App) BuiltInFormDecoder() *form.Decoder
- func (r *App) GetHTMLRender() HTMLRender
- func (r *App) HTMLRender(render HTMLRender)
- func (app *App) Mux() *chi.Mux
- func (app *App) NewRouter(path string) *Router
- func (l *App) RegisterContext(fn ContextFunc)
- func (l *App) RegisterCustomHandler(customType interface{}, fn CustomHandlerFunc)
- func (app *App) Run(addr string)
- func (app *App) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type Context
- type ContextFunc
- type Ctx
- func (c *Ctx) Abort()
- func (c *Ctx) AbortWithStatus(code int)
- func (c *Ctx) AbortWithStatusJSON(code int, jsonObj interface{})
- func (c *Ctx) AcceptedLanguages(lowercase bool) []string
- func (c *Ctx) Attachment(r io.Reader, filename string) (err error)
- func (c *Ctx) BaseContext() *Ctx
- func (c *Ctx) ClientIP() (clientIP string)
- func (c *Ctx) Data() M
- func (c *Ctx) Decode(v interface{}, args ...interface{}) (err error)
- func (c *Ctx) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Ctx) Get(key string) (value interface{}, exists bool)
- func (c *Ctx) GetQuery(name string) (string, bool)
- func (c *Ctx) HTML(name string, status ...int)
- func (c *Ctx) HTMLRender(render HTMLRender)
- func (c *Ctx) Inline(r io.Reader, filename string) (err error)
- func (c *Ctx) JSON(code int, i interface{}) (err error)
- func (c *Ctx) JSONBytes(code int, b []byte) (err error)
- func (c *Ctx) JSONP(code int, i interface{}, callback string) (err error)
- func (c *Ctx) MustParamInt(name string, d int) int
- func (c *Ctx) MustPostInt(key string, d int) int
- func (c *Ctx) MustPostString(key, d string) string
- func (c *Ctx) MustQueryInt(name string, d int) int
- func (c *Ctx) Next()
- func (c *Ctx) Param(name string) string
- func (c *Ctx) ParseForm() error
- func (c *Ctx) ParseMultipartForm(maxMemory int64) error
- func (c *Ctx) QueryParams() url.Values
- func (c *Ctx) Redirect(url string)
- func (c *Ctx) Render(statusCode int, r Render)
- func (c *Ctx) Request() *http.Request
- func (c *Ctx) RequestStart(w http.ResponseWriter, r *http.Request)
- func (c *Ctx) Response() *Response
- func (c *Ctx) Set(key string, value interface{})
- func (c *Ctx) SetData(data M)
- func (c *Ctx) SetHandlers(handlers []HandlerFunc)
- func (ctx *Ctx) Status(status int)
- func (c *Ctx) Stream(step func(w io.Writer) bool)
- func (c *Ctx) String(status int, format string, val ...interface{})
- func (c *Ctx) Text(code int, s string) error
- func (c *Ctx) TextBytes(code int, b []byte) (err error)
- func (c *Ctx) XML(code int, i interface{}) error
- func (c *Ctx) XMLBytes(code int, b []byte) (err error)
- type CustomHandlerFunc
- type HTMLRender
- type Handler
- type HandlerFunc
- type HandlersChain
- type M
- type Render
- type Response
- func (r *Response) CloseNotify() <-chan bool
- func (r *Response) Committed() bool
- func (r *Response) Flush()
- func (r *Response) Header() http.Header
- func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (r *Response) SetWriter(w http.ResponseWriter)
- func (r *Response) Size() int64
- func (r *Response) Status() int
- func (r *Response) Write(b []byte) (n int, err error)
- func (r *Response) WriteHeader(code int)
- func (w *Response) WriteHeaderNow()
- func (r *Response) WriteString(s string) (n int, err error)
- func (r *Response) Writer() http.ResponseWriter
- func (w *Response) Written() bool
- type ResponseWriter
- type Router
- func (r *Router) DELETE(path string, handlers ...Handler)
- func (r *Router) GET(path string, handlers ...Handler)
- func (r *Router) Group(path string, handlers ...Handler) *Router
- func (r *Router) HEAD(path string, handlers ...Handler)
- func (r *Router) HTTPHandlerFunc(h http.HandlerFunc) HandlerFunc
- func (r *Router) Handle(method, path string, handlers []Handler)
- func (r *Router) Mount(prefix string, handler http.Handler)
- func (r *Router) OPTIONS(path string, handlers ...Handler)
- func (r *Router) PATCH(path string, handlers ...Handler)
- func (r *Router) POST(path string, handlers ...Handler)
- func (r *Router) PUT(path string, handlers ...Handler)
- func (r *Router) RouteNotFound(h HandlerFunc)
- func (r *Router) Static(path string, root http.FileSystem, handlers ...HandlerFunc)
- func (r *Router) Use(middlewares ...Handler)
Constants ¶
const ( // CONNECT HTTP method CONNECT = http.MethodConnect // DELETE HTTP method DELETE = http.MethodDelete // GET HTTP method GET = http.MethodGet // HEAD HTTP method HEAD = http.MethodHead // OPTIONS HTTP method OPTIONS = http.MethodOptions // PATCH HTTP method PATCH = http.MethodPatch // POST HTTP method POST = http.MethodPost // PUT HTTP method PUT = http.MethodPut // TRACE HTTP method TRACE = http.MethodTrace ApplicationJSON = "application/json" ApplicationJSONCharsetUTF8 = ApplicationJSON + "; " + CharsetUTF8 ApplicationJavaScript = "application/javascript" ApplicationJavaScriptCharsetUTF8 = ApplicationJavaScript + "; " + CharsetUTF8 ApplicationXML = "application/xml" ApplicationXMLCharsetUTF8 = ApplicationXML + "; " + CharsetUTF8 ApplicationForm = "application/x-www-form-urlencoded" ApplicationProtobuf = "application/protobuf" ApplicationMsgpack = "application/msgpack" TextHTML = "text/html" TextHTMLCharsetUTF8 = TextHTML + "; " + CharsetUTF8 TextPlain = "text/plain" TextPlainCharsetUTF8 = TextPlain + "; " + CharsetUTF8 MultipartForm = "multipart/form-data" OctetStream = "application/octet-stream" CharsetUTF8 = "charset=utf-8" AcceptedLanguage = "Accept-Language" AcceptEncoding = "Accept-Encoding" Authorization = "Authorization" ContentDisposition = "Content-Disposition" ContentEncoding = "Content-Encoding" ContentLength = "Content-Length" ContentType = "Content-Type" Location = "Location" Upgrade = "Upgrade" Vary = "Vary" WWWAuthenticate = "WWW-Authenticate" XForwardedFor = "X-Forwarded-For" XRealIP = "X-Real-Ip" Allow = "Allow" Origin = "Origin" Gzip = "gzip" )
HTTP Constant Terms and Variables
Variables ¶
var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)
var DefaultWriter io.Writer = os.Stdout
var NativeChainHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { c := GetContext(w) b := c.BaseContext() b.request = r if b.index+1 < len(b.handlers) { c.Next() } })
Functions ¶
func GetPool ¶
func GetPool() *pool.BufferPool
func IsDebugging ¶
func IsDebugging() bool
IsDebugging returns true if the framework is running in debug mode. Use SetMode(gin.ReleaseMode) to disable debug mode.
Types ¶
type App ¶
type App struct { *Router // contains filtered or unexported fields }
func (*App) BuiltInFormDecoder ¶
BuiltInFormDecoder returns the built in form decoder github.com/go-playground/form in order for custom type to be registered.
func (*App) GetHTMLRender ¶
func (r *App) GetHTMLRender() HTMLRender
func (*App) HTMLRender ¶
func (r *App) HTMLRender(render HTMLRender)
HtmlTemplate use html template middleware
func (*App) RegisterContext ¶
func (l *App) RegisterContext(fn ContextFunc)
RegisterContext registers a custom Context function for creation and resetting of a global object passed per http request
func (*App) RegisterCustomHandler ¶
func (l *App) RegisterCustomHandler(customType interface{}, fn CustomHandlerFunc)
RegisterCustomHandler registers a custom handler that gets wrapped by HandlerFunc
type Context ¶
type Context interface { Request() *http.Request Response() *Response GetQuery(name string) (string, bool) Param(name string) string QueryParams() url.Values ParseForm() error ParseMultipartForm(maxMemory int64) error Next() ClientIP() (clientIP string) AcceptedLanguages(lowercase bool) []string Stream(step func(w io.Writer) bool) JSON(int, interface{}) error JSONBytes(int, []byte) error JSONP(int, interface{}, string) error XML(int, interface{}) error XMLBytes(int, []byte) error Text(int, string) error TextBytes(int, []byte) error Attachment(r io.Reader, filename string) (err error) Inline(r io.Reader, filename string) (err error) // Decode(includeFormQueryParams bool, maxMemory int64, v interface{}) (err error) Decode(v interface{}, args ...interface{}) (err error) BaseContext() *Ctx RequestStart(w http.ResponseWriter, r *http.Request) String(int, string, ...interface{}) // Custom SetHandlers([]HandlerFunc) Data() M SetData(M) Set(key string, value interface{}) Get(key string) (interface{}, bool) Abort() AbortWithStatus(code int) AbortWithStatusJSON(code int, jsonObj interface{}) Redirect(url string) // Render HTMLRender(HTMLRender) Render(code int, r Render) Status(code int) HTML(string, ...int) MustPostInt(key string, d int) int MustPostString(key string, d string) string MustParamInt(name string, d int) int MustQueryInt(name string, d int) int FormFile(name string) (*multipart.FileHeader, error) // contains filtered or unexported methods }
Context is the context interface type
func GetContext ¶
func GetContext(w http.ResponseWriter) Context
GetContext is a helper method for retrieving the Context object from the ResponseWriter when using native go hanlders. NOTE: this will panic if fed an http.ResponseWriter not provided by lars's chaining.
type ContextFunc ¶
ContextFunc is the function to run when creating a new context
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
func NewContext ¶
NewContext returns a new default lars Context object.
func (*Ctx) AbortWithStatus ¶
AbortWithStatus calls `Abort()` and writes the headers with the specified status code. For example, a failed attempt to authenticate a request could use: context.AbortWithStatus(401).
func (*Ctx) AbortWithStatusJSON ¶
AbortWithStatusJSON calls `Abort()` and then `JSON` internally. This method stops the chain, writes the status code and return a JSON body. It also sets the Content-Type as "application/json".
func (*Ctx) AcceptedLanguages ¶
AcceptedLanguages returns an array of accepted languages denoted by the Accept-Language header sent by the browser NOTE: some stupid browsers send in locales lowercase when all the rest send it properly
func (*Ctx) Attachment ¶
Attachment is a helper method for returning an attachement file to be downloaded, if you with to open inline see function
func (*Ctx) BaseContext ¶
BaseContext returns the underlying context object App uses internally. used when overriding the context object
func (*Ctx) ClientIP ¶
ClientIP implements a best effort algorithm to return the real client IP, it parses X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy.
func (*Ctx) Decode ¶
Decode takes the request and attempts to discover it's content type via the http headers and then decode the request body into the provided struct. Example if header was "application/json" would decode using json.NewDecoder(io.LimitReader(c.request.Body, maxMemory)).Decode(v).
func (*Ctx) HTMLRender ¶
func (c *Ctx) HTMLRender(render HTMLRender)
func (*Ctx) Inline ¶
Inline is a helper method for returning a file inline to be rendered/opened by the browser
func (*Ctx) JSONP ¶
JSONP sends a JSONP response with status code and uses `callback` to construct the JSONP payload.
func (*Ctx) MustPostString ¶
func (*Ctx) Next ¶
func (c *Ctx) Next()
Next should be used only inside middleware. It executes the pending handlers in the chain inside the calling handler.
func (*Ctx) ParseForm ¶
ParseForm calls the underlying http.Request ParseForm but also adds the URL params to the request Form as if they were defined as query params i.e. ?id=13&ok=true but does not add the params to the http.Request.URL.RawQuery for SEO purposes
func (*Ctx) ParseMultipartForm ¶
ParseMultipartForm calls the underlying http.Request ParseMultipartForm but also adds the URL params to the request Form as if they were defined as query params i.e. ?id=13&ok=true but does not add the params to the http.Request.URL.RawQuery for SEO purposes
func (*Ctx) QueryParams ¶
QueryParams returns the http.Request.URL.Query() values this function is not for convenience, but rather performance URL.Query() reparses the RawQuery every time it's called, but this function will cache the initial parsing so it doesn't have to reparse; which is useful if when accessing these Params from multiple middleware.
func (*Ctx) RequestStart ¶
func (c *Ctx) RequestStart(w http.ResponseWriter, r *http.Request)
RequestStart resets the Context to it's default request state
func (*Ctx) SetHandlers ¶
func (c *Ctx) SetHandlers(handlers []HandlerFunc)
type CustomHandlerFunc ¶
CustomHandlerFunc wraped by HandlerFunc and called where you can type cast both Context and Handler and call Handler
type HTMLRender ¶
type Handler ¶
type Handler interface{}
type internally.
func LastHandler ¶
Last returns the last handler in the chain. ie. the last handler is the main own.
type HandlerFunc ¶
type HandlerFunc func(Context)
HandlerFunc is the internal handler type used for middleware and handlers
type HandlersChain ¶
type HandlersChain []HandlerFunc
HandlersChain is an array of HanderFunc handlers to run
type Render ¶
type Render interface {
Render(w http.ResponseWriter, statusCode int)
}
type Response ¶
type Response struct { http.ResponseWriter // contains filtered or unexported fields }
Response struct contains methods and to capture extra data about the http request and more efficiently reset underlying writer object... it does comply with the http.ResponseWriter interface
func (*Response) CloseNotify ¶
CloseNotify wraps response writer's CloseNotify function.
func (*Response) Committed ¶
Committed returns whether the *Response header has already been written to and if has been committed to this return.
func (*Response) Header ¶
Header returns the header map that will be sent by WriteHeader. Changing the header after a call to WriteHeader (or Write) has no effect unless the modified headers were declared as trailers by setting the "Trailer" header before the call to WriteHeader (see example). To suppress implicit *Response headers, set their value to nil.
func (*Response) SetWriter ¶
func (r *Response) SetWriter(w http.ResponseWriter)
SetWriter sets the provided writer as the new *Response http.ResponseWriter
func (*Response) Write ¶
Write writes the data to the connection as part of an HTTP reply. If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK) before writing the data. If the Header does not contain a Content-Type line, Write adds a Content-Type set to the result of passing the initial 512 bytes of written data to DetectContentType.
func (*Response) WriteHeader ¶
WriteHeader sends an HTTP *Response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.
func (*Response) WriteHeaderNow ¶
func (w *Response) WriteHeaderNow()
func (*Response) WriteString ¶
WriteString write string to ResponseWriter
func (*Response) Writer ¶
func (r *Response) Writer() http.ResponseWriter
Writer return the *Response's http.ResponseWriter object. Usually only used when creating middleware.
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.Flusher http.CloseNotifier // Returns the HTTP response status code of the current request. Status() int // Returns the number of bytes already written into the response http body. // See Written() Size() int // Writes the string into the response body. WriteString(string) (int, error) // Returns true if the response body was already written. Written() bool // Forces to write the http header (status code + headers). WriteHeaderNow() // get the http.Pusher for server push Pusher() http.Pusher Before(func(ResponseWriter)) GetBefores() int }
ResponseWriter ...
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) HTTPHandlerFunc ¶
func (r *Router) HTTPHandlerFunc(h http.HandlerFunc) HandlerFunc
HandlerFunc convert http.HandlerFunc to ace.HandlerFunc
func (*Router) RouteNotFound ¶
func (r *Router) RouteNotFound(h HandlerFunc)
RouteNotFound call when route does not match
func (*Router) Static ¶
func (r *Router) Static(path string, root http.FileSystem, handlers ...HandlerFunc)
Static server static file path is url path root is root directory