Documentation
¶
Index ¶
- Constants
- type Context
- func (c *Context) BindJSON(obj interface{}) error
- func (c *Context) ClientIP() string
- func (c *Context) ContentType() string
- func (c *Context) Cookie(name string) (string, error)
- func (c *Context) Form(key string) string
- func (c *Context) FormFile(key string) (*multipart.FileHeader, error)
- func (c *Context) Get(key string) (interface{}, bool)
- func (c *Context) JSON(code int, i interface{}) error
- func (c *Context) MustGet(key string) interface{}
- func (c *Context) Param(name string) string
- func (c *Context) ParamInt(key string) (int, error)
- func (c *Context) Query(key string) string
- func (c *Context) QueryInt(key string) (int, error)
- func (c *Context) QueryIntWithDefault(key string, defaultValue int) (int, error)
- func (c *Context) Redirect(code int, location string) error
- func (c *Context) Render(code int, viewName string, data interface{}) error
- func (c *Context) RequestHeader(key string) string
- func (c *Context) RespHeader(key, value string)
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) (err error)
- func (c *Context) Set(key string, val interface{})
- func (c *Context) SetCookie(name string, value string, maxAge int, path string, domain string, secure bool, ...)
- func (c *Context) SetStatus(code int)
- func (c *Context) SetStdContext(ctx context.Context)
- func (c *Context) Status() int
- func (c *Context) StdContext() context.Context
- func (c *Context) String(code int, s string) error
- type ErrorHandler
- type HandlerFunc
- type MiddlewareFunc
- type MiddlewareHandler
- type Param
- type ResponseWriter
- type ServerOptions
- type WebServer
- func (s *WebServer) All(path string, handler HandlerFunc)
- func (s *WebServer) Delete(path string, handler HandlerFunc)
- func (s *WebServer) Get(path string, handler HandlerFunc)
- func (s *WebServer) Head(path string, handler HandlerFunc)
- func (s *WebServer) Options(path string, handler HandlerFunc)
- func (s *WebServer) Patch(path string, handler HandlerFunc)
- func (s *WebServer) Post(path string, handler HandlerFunc)
- func (s *WebServer) Put(path string, handler HandlerFunc)
- func (s *WebServer) Run(addr string) error
- func (s *WebServer) RunTLS(addr, cert, key string) error
- func (s *WebServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (s *WebServer) SetRender(templateRootPath string)
- func (s *WebServer) SetTemplate(t *template.Template)
- func (s *WebServer) Shutdown(ctx context.Context) error
- func (s *WebServer) Use(mHandler MiddlewareHandler)
- func (s *WebServer) UseFunc(aFunc func(c *Context, next HandlerFunc))
Constants ¶
const ( // CONNECT HTTP method CONNECT = "CONNECT" // DELETE HTTP method DELETE = "DELETE" // GET HTTP method GET = "GET" // HEAD HTTP method HEAD = "HEAD" // OPTIONS HTTP method OPTIONS = "OPTIONS" // PATCH HTTP method PATCH = "PATCH" // POST HTTP method POST = "POST" // PUT HTTP method PUT = "PUT" // TRACE HTTP method TRACE = "TRACE" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { WebServer *WebServer Request *http.Request Writer ResponseWriter // contains filtered or unexported fields }
Context represents the context of the current HTTP request. It holds request and response objects, path, path parameters, data and registered handler.
func FromContext ¶
FromContext return a web context from the standard context
func (*Context) BindJSON ¶
BindJSON binds the request body into provided type `obj`. The default binder does it based on Content-Type header.
func (*Context) 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. Use X-Forwarded-For before X-Real-Ip as nginx uses X-Real-Ip with the proxy's IP.
func (*Context) ContentType ¶
ContentType returns the Content-Type header of the request.
func (*Context) FormFile ¶
func (c *Context) FormFile(key string) (*multipart.FileHeader, error)
FormFile returns file.
func (*Context) MustGet ¶
MustGet returns the value for the given key if it exists, otherwise it panics.
func (*Context) QueryIntWithDefault ¶
QueryIntWithDefault returns query parameter by key and cast the value to int. If the value doesn't exist, the default value will be used.
func (*Context) RequestHeader ¶
RequestHeader is a intelligent shortcut for c.Request.Header.Get(key)
func (*Context) RespHeader ¶
RespHeader is a intelligent shortcut for c.Writer.Header().Set(key, value) It writes a header in the response. If value == "", this method removes the header `c.Writer.Header().Del(key)`
func (*Context) SaveUploadedFile ¶
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) (err error)
SaveUploadedFile uploads the form file to specific dst.
func (*Context) Set ¶
Set saves data in the context. It also lazy initializes c.Keys if it was not used previously.
func (*Context) SetCookie ¶
func (c *Context) SetCookie( name string, value string, maxAge int, path string, domain string, secure bool, httpOnly bool, )
SetCookie allows us to create an cookie
func (*Context) SetStdContext ¶
SetStdContext allow us to save the golang context to request
func (*Context) StdContext ¶
StdContext return golang standard context
type ErrorHandler ¶
ErrorHandler defines a function to handle HTTP errors
type HandlerFunc ¶
HandlerFunc defines a function to server HTTP requests
func WrapHandler ¶
func WrapHandler(h http.Handler) HandlerFunc
WrapHandler wraps `http.Handler` into `web.HandlerFunc`.
type MiddlewareFunc ¶
type MiddlewareFunc func(c *Context, next HandlerFunc)
MiddlewareFunc is an adapter to allow the use of ordinary functions as WebServer handlers.
func (MiddlewareFunc) Invoke ¶
func (m MiddlewareFunc) Invoke(c *Context, next HandlerFunc)
Invoke function is a middleware entry
type MiddlewareHandler ¶
type MiddlewareHandler interface {
Invoke(c *Context, next HandlerFunc)
}
MiddlewareHandler is an interface that objects can implement to be registered to serve as middleware in the WebServer middleware stack.
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter ContentLength() int Status() int // contains filtered or unexported methods }
ResponseWriter wraps the original http.ResponseWriter
type ServerOptions ¶
type WebServer ¶
type WebServer struct { MaxRequestBodySize int64 ErrorHandler ErrorHandler NotFoundHandler HandlerFunc // contains filtered or unexported fields }
WebServer is root level of framework instance
func NewServer ¶
func NewServer(mHandlers ...MiddlewareHandler) *WebServer
NewServer returns a new WebServer instance
func (*WebServer) All ¶
func (s *WebServer) All(path string, handler HandlerFunc)
All is a shortcut for adding all methods
func (*WebServer) Delete ¶
func (s *WebServer) Delete(path string, handler HandlerFunc)
Delete is a shortcut for router.Add("DELETE", path, handle)
func (*WebServer) Get ¶
func (s *WebServer) Get(path string, handler HandlerFunc)
Get is a shortcut for router.Add("GET", path, handle)
func (*WebServer) Head ¶
func (s *WebServer) Head(path string, handler HandlerFunc)
Head is a shortcut for router.Add("HEAD", path, handle)
func (*WebServer) Options ¶
func (s *WebServer) Options(path string, handler HandlerFunc)
Options is a shortcut for router.Add("OPTIONS", path, handle)
func (*WebServer) Patch ¶
func (s *WebServer) Patch(path string, handler HandlerFunc)
Patch is a shortcut for router.Add("PATCH", path, handle)
func (*WebServer) Post ¶
func (s *WebServer) Post(path string, handler HandlerFunc)
Post is a shortcut for router.Add("POST", path, handle)
func (*WebServer) Put ¶
func (s *WebServer) Put(path string, handler HandlerFunc)
Put is a shortcut for router.Add("PUT", path, handle)
func (*WebServer) ServeHTTP ¶
func (s *WebServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
Conforms to the http.Handler interface.
func (*WebServer) SetTemplate ¶
SetTemplate function allows user to set their own template instance.
func (*WebServer) Use ¶
func (s *WebServer) Use(mHandler MiddlewareHandler)
Use adds a Handler onto the middleware stack. Handlers are invoked in the order they are added to a WebServer.
func (*WebServer) UseFunc ¶
func (s *WebServer) UseFunc(aFunc func(c *Context, next HandlerFunc))
UseFunc adds an anonymous function onto middleware stack.