Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultSkipper(c *Context) bool
- func GetClientIP(req *http.Request) string
- func GetRealIP(req *http.Request) string
- func GetRemoteAddr(req *http.Request) string
- func IsPrivateIP(ip net.IP) bool
- type AtomicSignedKeys
- type Cod
- func (d *Cod) ALL(path string, handlerList ...Handler)
- func (d *Cod) AddGroup(g *Group)
- func (d *Cod) AddValidator(key string, fn Validator)
- 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) Pre(handlerList ...PreHandler)
- 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) AddRequestHeader(key, value string)
- func (c *Context) AddSignedCookie(cookie *http.Cookie) (err error)
- func (c *Context) CacheMaxAge(age string)
- func (c *Context) CacheSMaxAge(age, sMaxAge string)
- func (c *Context) ClientIP() string
- func (c *Context) 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) IsReaderBody() bool
- 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) Pass(another *Cod)
- func (c *Context) Pipe(r io.Reader) (written int64, err error)
- 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) RefreshSignedCookie(name string) (err error)
- func (c *Context) RemoteAddr() string
- func (c *Context) Reset()
- func (c *Context) ResetHeader()
- func (c *Context) Set(key, value interface{})
- func (c *Context) SetContentTypeByExt(file string)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetRequestHeader(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 PreHandler
- type RWMutexSignedKeys
- type Router
- type RouterInfo
- type SignedKeysGenerator
- type SimpleSignedKeys
- type Skipper
- type TraceInfo
- type TraceInfos
- type TraceListener
- type Validator
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" // HeaderContentLength content length HeaderContentLength = "Content-Length" // 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" // HeaderTransferEncoding transfer encoding HeaderTransferEncoding = "Transfer-Encoding" // 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, } // ErrNilResponse nil response ErrNilResponse = &hes.Error{ StatusCode: 500, Message: "nil response", Category: ErrCategoryCod, } // ErrNotSupportPush not support http push ErrNotSupportPush = &hes.Error{ StatusCode: 500, Message: "not support http push", 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)
func GetClientIP ¶ added in v0.1.5
GetClientIP get client ip
func GetRemoteAddr ¶ added in v0.1.5
GetRemoteAddr get remote addr
func IsPrivateIP ¶ added in v0.1.2
IsPrivateIP check the ip is private
Types ¶
type AtomicSignedKeys ¶ added in v0.1.4
type AtomicSignedKeys struct {
// contains filtered or unexported fields
}
AtomicSignedKeys atomic toggle signed keys
func (*AtomicSignedKeys) GetKeys ¶ added in v0.1.4
func (atSk *AtomicSignedKeys) GetKeys() []string
GetKeys get keys
func (*AtomicSignedKeys) SetKeys ¶ added in v0.1.4
func (atSk *AtomicSignedKeys) SetKeys(keys []string)
SetKeys set keys
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 // PreMiddlewares pre middleware function PreMiddlewares []PreHandler // 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 // SignedKeys signed keys SignedKeys SignedKeysGenerator // contains filtered or unexported fields }
Cod web framework instance
func NewWithoutServer ¶
func NewWithoutServer() *Cod
NewWithoutServer create a cod instance without server
func (*Cod) AddValidator ¶ added in v0.1.0
AddValidator add validate function
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) Pre ¶ added in v0.1.5
func (d *Cod) Pre(handlerList ...PreHandler)
Pre add pre middleware function handler
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) AddRequestHeader ¶ added in v0.0.5
AddRequestHeader add http request header
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) CacheSMaxAge ¶ added in v0.1.0
CacheSMaxAge set http response to cache for s-max age
func (*Context) ClientIP ¶ added in v0.1.2
ClientIP get the client ip get the first public ip from x-forwarded-for --> x-real-ip if not found, then get remote addr
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) IsReaderBody ¶ added in v0.1.3
IsReaderBody check body is reader
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) RefreshSignedCookie ¶ added in v0.1.4
RefreshSignedCookie refresh signed cookie
func (*Context) ResetHeader ¶ added in v0.0.5
func (c *Context) ResetHeader()
ResetHeader reset response header
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) SetRequestHeader ¶ added in v0.0.5
SetRequestHeader set http request header
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 RWMutexSignedKeys ¶ added in v0.1.4
RWMutexSignedKeys read/write mutex signed key
func (*RWMutexSignedKeys) GetKeys ¶ added in v0.1.4
func (rwSk *RWMutexSignedKeys) GetKeys() []string
GetKeys get keys
func (*RWMutexSignedKeys) SetKeys ¶ added in v0.1.4
func (rwSk *RWMutexSignedKeys) SetKeys(keys []string)
SetKeys set keys
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 SignedKeysGenerator ¶ added in v0.1.4
SignedKeysGenerator signed keys generator
type SimpleSignedKeys ¶ added in v0.1.4
type SimpleSignedKeys struct {
// contains filtered or unexported fields
}
SimpleSignedKeys simple sigined key
func (*SimpleSignedKeys) GetKeys ¶ added in v0.1.4
func (sk *SimpleSignedKeys) GetKeys() []string
GetKeys get keys
func (*SimpleSignedKeys) SetKeys ¶ added in v0.1.4
func (sk *SimpleSignedKeys) SetKeys(keys []string)
SetKeys set keys
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) string
ServerTiming trace infos to server timing