Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultSkipper(c *Context) bool
- type Cod
- func (d *Cod) ALL(path string, handlerList ...Handler)
- func (d *Cod) AddGroup(g *Group)
- func (d *Cod) Close() error
- func (d *Cod) DELETE(path string, handlerList ...Handler)
- func (d *Cod) EmitError(c *Context, err error)
- func (d *Cod) EmitTrace(c *Context, infos TraceInfos)
- func (d *Cod) Error(c *Context, err error)
- func (d *Cod) GET(path string, handlerList ...Handler)
- func (d *Cod) GetFunctionName(fn interface{}) string
- func (d *Cod) GetStatus() int32
- func (d *Cod) GracefulClose(delay time.Duration) error
- func (d *Cod) HEAD(path string, handlerList ...Handler)
- func (d *Cod) Handle(method, path string, handlerList ...Handler)
- func (d *Cod) ListenAndServe(addr string) error
- func (d *Cod) NotFound(resp http.ResponseWriter, req *http.Request)
- func (d *Cod) OPTIONS(path string, handlerList ...Handler)
- func (d *Cod) OnError(ln ErrorListener)
- func (d *Cod) OnTrace(ln TraceListener)
- func (d *Cod) PATCH(path string, handlerList ...Handler)
- func (d *Cod) POST(path string, handlerList ...Handler)
- func (d *Cod) PUT(path string, handlerList ...Handler)
- func (d *Cod) Serve(l net.Listener) error
- func (d *Cod) ServeHTTP(resp http.ResponseWriter, req *http.Request)
- func (d *Cod) SetFunctionName(fn interface{}, name string)
- func (d *Cod) TRACE(path string, handlerList ...Handler)
- func (d *Cod) Use(handlerList ...Handler)
- type Context
- func (c *Context) AddCookie(cookie *http.Cookie) error
- func (c *Context) AddHeader(key, value string)
- func (c *Context) AddSignedCookie(cookie *http.Cookie) (err error)
- func (c *Context) CacheMaxAge(age string)
- func (c *Context) Cod(d *Cod) *Cod
- func (c *Context) Cookie(name string) (*http.Cookie, error)
- func (c *Context) Created(body interface{})
- func (c *Context) DisableReuse()
- func (c *Context) Get(key interface{}) interface{}
- func (c *Context) GetHeader(key string) string
- func (c *Context) GetRequestHeader(key string) string
- func (c *Context) Header() http.Header
- func (c *Context) NoCache()
- func (c *Context) NoContent()
- func (c *Context) NoStore()
- func (c *Context) NotModified()
- func (c *Context) Param(name string) string
- func (c *Context) Push(target string, opts *http.PushOptions) (err error)
- func (c *Context) Query() map[string]string
- func (c *Context) QueryParam(name string) string
- func (c *Context) RealIP() string
- func (c *Context) Redirect(code int, url string) (err error)
- func (c *Context) RemoteAddr() string
- func (c *Context) Reset()
- func (c *Context) Set(key, value interface{})
- func (c *Context) SetContentTypeByExt(file string)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SignedCookie(name string) (cookie *http.Cookie, err error)
- func (c *Context) Write(buf []byte) (int, error)
- func (c *Context) WriteHeader(statusCode int)
- type ErrorHandler
- type ErrorListener
- type GenerateID
- type Group
- func (g *Group) ALL(path string, handlerList ...Handler)
- func (g *Group) DELETE(path string, handlerList ...Handler)
- func (g *Group) GET(path string, handlerList ...Handler)
- func (g *Group) HEAD(path string, handlerList ...Handler)
- func (g *Group) OPTIONS(path string, handlerList ...Handler)
- func (g *Group) PATCH(path string, handlerList ...Handler)
- func (g *Group) POST(path string, handlerList ...Handler)
- func (g *Group) PUT(path string, handlerList ...Handler)
- func (g *Group) TRACE(path string, handlerList ...Handler)
- type Handler
- type Router
- type RouterInfo
- type Skipper
- type TraceInfo
- type TraceInfos
- type TraceListener
Constants ¶
const ( // StatusRunning running status StatusRunning = iota // StatusClosing closing status StatusClosing // StatusClosed closed status StatusClosed )
const ( // ErrCategoryCod cod category ErrCategoryCod = "cod" // HeaderXForwardedFor x-forwarded-for HeaderXForwardedFor = "X-Forwarded-For" // HeaderXRealIp x-real-ip HeaderXRealIp = "X-Real-Ip" // HeaderSetCookie Set-Cookie HeaderSetCookie = "Set-Cookie" // HeaderLocation Location HeaderLocation = "Location" // HeaderContentType Content-Type HeaderContentType = "Content-Type" // HeaderAuthorization Authorization HeaderAuthorization = "Authorization" // HeaderWWWAuthenticate WWW-Authenticate HeaderWWWAuthenticate = "WWW-Authenticate" // HeaderCacheControl Cache-Control HeaderCacheControl = "Cache-Control" // HeaderETag ETag HeaderETag = "ETag" // HeaderLastModified last modified HeaderLastModified = "Last-Modified" // HeaderContentEncoding content encoding HeaderContentEncoding = "Content-Encoding" // HeaderIfModifiedSince if modified since HeaderIfModifiedSince = "If-Modified-Since" // HeaderIfNoneMatch if none match HeaderIfNoneMatch = "If-None-Match" // HeaderAcceptEncoding accept encoding HeaderAcceptEncoding = "Accept-Encoding" // HeaderServerTiming server timing HeaderServerTiming = "Server-Timing" // MinRedirectCode min redirect code MinRedirectCode = 300 // MaxRedirectCode max redirect code MaxRedirectCode = 308 // MIMETextPlain text plain MIMETextPlain = "text/plain; charset=UTF-8" // MIMEApplicationJSON application json MIMEApplicationJSON = "application/json; charset=UTF-8" // MIMEBinary binary data MIMEBinary = "application/octet-stream" // Gzip gzip compress Gzip = "gzip" // Br brotli compress Br = "br" )
Variables ¶
var ( // ErrInvalidRedirect invalid redirect ErrInvalidRedirect = &hes.Error{ StatusCode: 400, Message: "invalid redirect", Category: ErrCategoryCod, } // ErrNillResponse nil response ErrNillResponse = &hes.Error{ StatusCode: 500, Message: "nil response", Category: ErrCategoryCod, } )
var ( // ServerTimingDur server timing dur ServerTimingDur = []byte(";dur=") // ServerTimingDesc server timing desc ServerTimingDesc = []byte(`;desc="`) // ServerTimingEnd server timing end ServerTimingEnd = []byte(`"`) )
Functions ¶
func DefaultSkipper ¶
DefaultSkipper default skipper function(not skip)
Types ¶
type Cod ¶
type Cod struct {
// Server http server
Server *http.Server
// Router http router
Router *httprouter.Router
// Routers all router infos
Routers []*RouterInfo
// Middlewares middleware function
Middlewares []Handler
// ErrorHandler set the function for error handler
ErrorHandler ErrorHandler
// NotFoundHandler set the function for not found handler
NotFoundHandler http.HandlerFunc
// GenerateID generate id function, will use it for create id for context
GenerateID GenerateID
// EnableTrace enable trace
EnableTrace bool
// Keys signed cookie keys
Keys []string
// contains filtered or unexported fields
}
Cod web framework instance
func NewWithoutServer ¶
func NewWithoutServer() *Cod
NewWithoutServer create a cod instance without server
func (*Cod) GetFunctionName ¶
GetFunctionName get function name
func (*Cod) GracefulClose ¶
GracefulClose graceful close the http server
func (*Cod) ListenAndServe ¶
ListenAndServe listen and serve for http server
func (*Cod) NotFound ¶
func (d *Cod) NotFound(resp http.ResponseWriter, req *http.Request)
NotFound not found handle
func (*Cod) ServeHTTP ¶
func (d *Cod) ServeHTTP(resp http.ResponseWriter, req *http.Request)
ServeHTTP http handler
func (*Cod) SetFunctionName ¶
SetFunctionName set function name
type Context ¶
type Context struct {
Request *http.Request
Response http.ResponseWriter
// Headers http response's header
Headers http.Header
// Committed commit the data to response
Committed bool
// ID context id
ID string
// Route route path
Route string
// Next next function
Next func() error
// Params uri params
Params map[string]string
// RawParams http router params
RawParams httprouter.Params
// StatusCode http response's status code
StatusCode int
// Body http response's body
Body interface{}
// BodyBuffer http response's body buffer
BodyBuffer *bytes.Buffer
// RequestBody http request body
RequestBody []byte
// contains filtered or unexported fields
}
Context cod context
func NewContext ¶
func NewContext(resp http.ResponseWriter, req *http.Request) *Context
NewContext new a context
func (*Context) AddSignedCookie ¶
AddSignedCookie add the signed cookie to the response
func (*Context) CacheMaxAge ¶
CacheMaxAge set http response to cache for max age
func (*Context) DisableReuse ¶ added in v0.0.2
func (c *Context) DisableReuse()
DisableReuse set the context disable reuse
func (*Context) Get ¶
func (c *Context) Get(key interface{}) interface{}
Get get the value from context
func (*Context) GetRequestHeader ¶
GetRequestHeader get from http request header
func (*Context) Push ¶
func (c *Context) Push(target string, opts *http.PushOptions) (err error)
Push http server push
func (*Context) Query ¶
Query get the query map. It will return map[string]string, not the same as url.Values
func (*Context) QueryParam ¶
QueryParam get the query value
func (*Context) Set ¶
func (c *Context) Set(key, value interface{})
Set store the value in the context
func (*Context) SetContentTypeByExt ¶
SetContentTypeByExt set content type by file extname
func (*Context) SignedCookie ¶
SignedCookie get signed cookie from http request
func (*Context) WriteHeader ¶
WriteHeader set the http status code
type Group ¶
Group group router
type Router ¶
type Router struct {
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
HandleList []Handler `json:"-"`
}
Router router
type RouterInfo ¶
type RouterInfo struct {
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
}
RouterInfo router's info
type TraceInfo ¶
type TraceInfo struct {
Name string `json:"name,omitempty"`
Duration time.Duration `json:"duration,omitempty"`
}
TraceInfo trace's info
type TraceInfos ¶
type TraceInfos []*TraceInfo
TraceInfos trace infos
func (TraceInfos) ServerTiming ¶
func (traceInfos TraceInfos) ServerTiming(prefix string) []byte
ServerTiming trace infos to server timing