Documentation ¶
Index ¶
- func NotFoundHandler(c *Context) (err error)
- func WithLogger(name string) negroni.Handler
- type Context
- func (c *Context) AddHeader(key, value string)
- func (c *Context) Attachment(file, name string) error
- func (c *Context) Blob(code int, contentType string, b []byte) (err error)
- func (c *Context) Cookie(name string) (*http.Cookie, error)
- func (c *Context) CookieValue(n string) string
- func (c *Context) Cookies() []*http.Cookie
- func (c *Context) Error(code int, msg string) (err error)
- func (c *Context) File(file string) (err error)
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) FormParams() (url.Values, error)
- func (c *Context) FormValue(name string) string
- func (c *Context) GetQueryArray(name string) ([]string, bool)
- func (c *Context) GetQueryParam(name string) (string, bool)
- func (c *Context) Header(name string) string
- func (c *Context) Inline(file, name string) error
- func (c *Context) JSON(code int, i interface{}) error
- func (c *Context) JSONBlob(code int, b []byte) (err error)
- func (c *Context) JSONPretty(code int, i interface{}, indent string) (err error)
- func (c *Context) MultipartForm() (*multipart.Form, error)
- func (c *Context) Param(name string) string
- func (c *Context) QueryParam(name string) string
- func (c *Context) QueryParams() url.Values
- func (c *Context) QueryString() string
- func (c *Context) ReadAndValidate(vals interface{}) (status int, err error)
- func (c *Context) ReadAndValidateJSON(res interface{}) (code int, err error)
- func (c *Context) ReadJSON(res interface{}) (code int, err error)
- func (c *Context) ReadParams(vals interface{}) (status int, err error)
- func (c *Context) Redirect(code int, url string) error
- func (c *Context) Request() *http.Request
- func (c *Context) Response() http.ResponseWriter
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) Stream(code int, contentType string, r io.Reader) (err error)
- func (c *Context) String(code int, s string) error
- type ContextHandlerFunc
- type HttpHelper
- func (hr *HttpHelper) NotFoundHandler(h http.Handler)
- func (h *HttpHelper) Run(addr ...string)
- func (h *HttpHelper) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *HttpHelper) Use(handler negroni.Handler)
- func (h *HttpHelper) UseFunc(handlerFunc negroni.HandlerFunc)
- func (h *HttpHelper) UseHandler(handler http.Handler)
- func (h *HttpHelper) UseHandlerFunc(handlerFunc http.HandlerFunc)
- type RouterGroup
- func (g *RouterGroup) DELETE(path string, h func(c *Context))
- func (g *RouterGroup) Delete(path string, h http.HandlerFunc)
- func (g *RouterGroup) GET(pattern string, h func(c *Context))
- func (g *RouterGroup) Get(pattern string, h http.HandlerFunc)
- func (g *RouterGroup) Group(relPath string) *RouterGroup
- func (g *RouterGroup) HEAD(path string, h func(c *Context))
- func (g *RouterGroup) Head(path string, h http.HandlerFunc)
- func (g *RouterGroup) OPTIONS(path string, h func(c *Context))
- func (g *RouterGroup) Options(path string, h http.HandlerFunc)
- func (g *RouterGroup) PATCH(path string, h func(c *Context))
- func (g *RouterGroup) POST(path string, h func(c *Context))
- func (g *RouterGroup) PUT(path string, h func(c *Context))
- func (g *RouterGroup) Patch(path string, h http.HandlerFunc)
- func (g *RouterGroup) Post(path string, h http.HandlerFunc)
- func (g *RouterGroup) Put(path string, h http.HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NotFoundHandler ¶
func WithLogger ¶ added in v0.1.2
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func NewHttpContext ¶
func NewHttpContext(w http.ResponseWriter, r *http.Request) *Context
func (*Context) Attachment ¶
func (*Context) CookieValue ¶ added in v0.0.6
func (*Context) GetQueryArray ¶ added in v0.0.4
func (*Context) GetQueryParam ¶ added in v0.0.4
func (*Context) JSONPretty ¶
func (*Context) QueryParam ¶
func (*Context) QueryParams ¶
func (*Context) QueryString ¶
func (*Context) ReadAndValidate ¶ added in v0.2.0
read values from path, query string, form, header or cookie, store them in a struct specified by vals, then values are validated by using "github.com/go-playground/validator/v10". param name is specified by field tag. e.g.
var vals struct { V1 int `path:"v1" validate:"gt=0"` // read path param "v1", the value must be greater than 0 V2 bool `query:"v2"` // read query param "v2=xxx" V3 string `form:"v3" validate:"required"` // read form param "v3=xxx", V4 int `header:"Content-Length"` // read header "Content-Length" V5 []byte `cookie:"v5"` // read cookie "v4" }
if status, err := c.ReadAndValidate(&vals); err != nil { c.Error(status, err.Error()) return }
func (*Context) ReadAndValidateJSON ¶ added in v0.2.1
func (*Context) ReadParams ¶ added in v0.0.4
read values from path, query string, form, header or cookie, store them in a struct specified by vals. param name is specified by field tag. e.g.
var vals struct { V1 int `path:"v1" optional` // read path param "v1" optionally, any integer type (u)int8/16/32/64 is acceptable V2 bool `query:"v2" ignore-error` // read query param "v2=xxx", ignore error occurring V3 string `form:"v3"` // read form param "v3=xxx", type string can be replace with []byte V4 int `header:"Content-Length"` // read header "Content-Length" V5 []byte `cookie:"v5" optional` // read cookie "v4" opiontally }
if status, err := c.ReadParams(&vals); err != nil { c.Error(status, err.Error()) return }
func (*Context) Response ¶
func (c *Context) Response() http.ResponseWriter
type ContextHandlerFunc ¶
type ContextHandlerFunc func(c *Context)
type HttpHelper ¶
type HttpHelper struct { RouterGroup // contains filtered or unexported fields }
func NewHelper ¶
func NewHelper(handlers ...negroni.Handler) *HttpHelper
func (*HttpHelper) NotFoundHandler ¶
func (hr *HttpHelper) NotFoundHandler(h http.Handler)
func (*HttpHelper) Run ¶
func (h *HttpHelper) Run(addr ...string)
func (*HttpHelper) ServeHTTP ¶
func (h *HttpHelper) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*HttpHelper) Use ¶
func (h *HttpHelper) Use(handler negroni.Handler)
func (*HttpHelper) UseFunc ¶ added in v0.0.2
func (h *HttpHelper) UseFunc(handlerFunc negroni.HandlerFunc)
func (*HttpHelper) UseHandler ¶
func (h *HttpHelper) UseHandler(handler http.Handler)
func (*HttpHelper) UseHandlerFunc ¶
func (h *HttpHelper) UseHandlerFunc(handlerFunc http.HandlerFunc)
type RouterGroup ¶ added in v0.1.0
type RouterGroup struct {
// contains filtered or unexported fields
}
func (*RouterGroup) DELETE ¶ added in v0.1.0
func (g *RouterGroup) DELETE(path string, h func(c *Context))
func (*RouterGroup) Delete ¶ added in v0.1.0
func (g *RouterGroup) Delete(path string, h http.HandlerFunc)
func (*RouterGroup) GET ¶ added in v0.1.0
func (g *RouterGroup) GET(pattern string, h func(c *Context))
------ context -----
func (*RouterGroup) Get ¶ added in v0.1.0
func (g *RouterGroup) Get(pattern string, h http.HandlerFunc)
func (*RouterGroup) Group ¶ added in v0.1.0
func (g *RouterGroup) Group(relPath string) *RouterGroup
func (*RouterGroup) HEAD ¶ added in v0.1.0
func (g *RouterGroup) HEAD(path string, h func(c *Context))
func (*RouterGroup) Head ¶ added in v0.1.0
func (g *RouterGroup) Head(path string, h http.HandlerFunc)
func (*RouterGroup) OPTIONS ¶ added in v0.1.0
func (g *RouterGroup) OPTIONS(path string, h func(c *Context))
func (*RouterGroup) Options ¶ added in v0.1.0
func (g *RouterGroup) Options(path string, h http.HandlerFunc)
func (*RouterGroup) PATCH ¶ added in v0.1.0
func (g *RouterGroup) PATCH(path string, h func(c *Context))
func (*RouterGroup) POST ¶ added in v0.1.0
func (g *RouterGroup) POST(path string, h func(c *Context))
func (*RouterGroup) PUT ¶ added in v0.1.0
func (g *RouterGroup) PUT(path string, h func(c *Context))
func (*RouterGroup) Patch ¶ added in v0.1.0
func (g *RouterGroup) Patch(path string, h http.HandlerFunc)
func (*RouterGroup) Post ¶ added in v0.1.0
func (g *RouterGroup) Post(path string, h http.HandlerFunc)
func (*RouterGroup) Put ¶ added in v0.1.0
func (g *RouterGroup) Put(path string, h http.HandlerFunc)
----- HandlerFunc ----
Click to show internal directories.
Click to hide internal directories.