Documentation ¶
Index ¶
- Constants
- type Config
- type Ctx
- func (c *Ctx) AddHeader(key string, value string) *Ctx
- func (c *Ctx) Body() []byte
- func (c *Ctx) BodyParser(out interface{}) error
- func (c *Ctx) ClearCookie(name string) *Ctx
- func (c *Ctx) Cookies() []*http.Cookie
- func (c *Ctx) FormFile(key string) (*multipart.FileHeader, error)
- func (c *Ctx) FormValue(key string, defaultValue ...string) string
- func (c *Ctx) Get(key string) interface{}
- func (c *Ctx) GetCookie(name string) *http.Cookie
- func (c *Ctx) GetHeader(key string, defaultValue ...string) string
- func (c *Ctx) GetHeaderValues(key string, defaultValue ...[]string) []string
- func (c *Ctx) GetParam(key string, defaultValue ...string) string
- func (c *Ctx) GetQuery(key string, defaultValue ...string) string
- func (c *Ctx) Header() http.Header
- func (c *Ctx) Html(html string) error
- func (c *Ctx) Json(data interface{}) error
- func (c *Ctx) Method() string
- func (c *Ctx) Next() error
- func (c *Ctx) Params() map[string]string
- func (c *Ctx) Query() url.Values
- func (c *Ctx) Redirect(target string, status ...int) error
- func (c *Ctx) SendFile(path string, download bool, fs ...http.FileSystem) error
- func (c *Ctx) SendStatus(status int) error
- func (c *Ctx) Set(key string, value interface{})
- func (c *Ctx) SetCookie(cookie *http.Cookie) *Ctx
- func (c *Ctx) SetHeader(key string, value string) *Ctx
- func (c *Ctx) Status(status int) *Ctx
- func (c *Ctx) Stream(data []byte) error
- func (c *Ctx) String(format string, values ...interface{}) error
- func (c *Ctx) Url() *url.URL
- type Error
- type ErrorHandlerFunc
- type FileSystem
- type HandlerFunc
- type Kid
- func (g Kid) Delete(pattern string, handler HandlerFunc)
- func (g Kid) Get(pattern string, handler HandlerFunc)
- func (g Kid) Group(prefix string) *group
- func (g Kid) Head(pattern string, handler HandlerFunc)
- func (k *Kid) Listen(addr string) (err error)
- func (k *Kid) ListenTLS(addr string, certFile string, keyFile string) (err error)
- func (g Kid) Patch(pattern string, handler HandlerFunc)
- func (g Kid) Post(pattern string, handler HandlerFunc)
- func (g Kid) Put(pattern string, handler HandlerFunc)
- func (g Kid) Use(middlewares ...HandlerFunc)
- type Logger
- type LoggerLevel
Constants ¶
View Source
const ( HeaderRequestId = "X-Request-ID" HeaderContentDisposition = "Content-Disposition" HeaderContentType = "Content-Type" HeaderLocation = "Location" HeaderAuthorization = "Authorization" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderOrigin = "Origin" HeaderVary = "Vary" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" )
Http header
View Source
const ( CtxRequestId = "Ctx-Request-ID" CtxBasicAuthUsername = "Ctx-Basic-Auth-Username" CtxBasicAuthPassword = "Ctx-Basic-Auth-Password" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // ErrorHandler is executed when an error is returned from kid.HandlerFunc. // // Default: DefaultErrorHandler ErrorHandler ErrorHandlerFunc }
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
func (*Ctx) BodyParser ¶
BodyParser parsers body to any struct.
func (*Ctx) FormFile ¶
func (c *Ctx) FormFile(key string) (*multipart.FileHeader, error)
FormFile gets a form file by key.
func (*Ctx) GetHeaderValues ¶
GetHeaderValues gets a header by key.
func (*Ctx) SendStatus ¶
SendStatus sets response's status and send.
type Error ¶
type Error struct { // Http status Status int // Message to show Message string // Extra data Data interface{} }
type ErrorHandlerFunc ¶
ErrorHandlerFunc defines a function to process return errors or panic errors from handlers.
var DefaultErrorHandler ErrorHandlerFunc = func(c *Ctx, err error) error { message := fmt.Sprintf("%s %s", c.Method(), c.Url().RequestURI()) if e, ok := err.(*Error); ok { errorLogger.Error(c, message, map[string]interface{}{ "data": e.Data, }, e) return c.Status(e.Status).String(e.Message) } else { errorLogger.Error(c, message, nil, err) return c.Status(http.StatusInternalServerError).String(err.Error()) } }
DefaultErrorHandler that process return errors or panic errors from handlers.
type FileSystem ¶ added in v0.6.0
type FileSystem struct { // Index page filename, default: index.html Index string // Root dir, default: os.Getwd() Root string // Enable open file out of root path, default: false EnableOuter bool // FS that implement http.FileSystem, default: os FS http.FileSystem }
Filesystem implement http.FileSystem
type HandlerFunc ¶
HandlerFunc defines a function to serve HTTP requests.
type Kid ¶
type Kid struct {
// contains filtered or unexported fields
}
Kid application.
func (Kid) Delete ¶
func (g Kid) Delete(pattern string, handler HandlerFunc)
Delete adds a delete router.
func (Kid) Patch ¶
func (g Kid) Patch(pattern string, handler HandlerFunc)
Patch adds a patch router.
type Logger ¶ added in v0.6.0
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) FormatMessage ¶ added in v0.6.0
type LoggerLevel ¶ added in v0.6.0
type LoggerLevel string
const ( LoggerLevelInfo LoggerLevel = "info" LoggerLevelError LoggerLevel = "error" )
Source Files ¶
Click to show internal directories.
Click to hide internal directories.