Documentation ¶
Index ¶
- Constants
- Variables
- func LogReleaseCtr(c *Context) *zap.Logger
- func LogWithCtr(c *Context) *zap.Logger
- type Blade
- func (b *Blade) Any(path string, handler Handler)
- func (b *Blade) BindMiddleware()
- func (b *Blade) Delete(path string, handler Handler)
- func (b *Blade) EnableLogRequest()
- func (b *Blade) Get(path string, handler Handler)
- func (b *Blade) Gzip() bool
- func (b *Blade) Head(path string, handler Handler)
- func (b *Blade) NoFunc(f func(*Context))
- func (b *Blade) OnEnd(callback func())
- func (b *Blade) OnError(callback func(*Context, error))
- func (b *Blade) OnStart(callback func())
- func (b *Blade) Options(path string, handler Handler)
- func (b *Blade) Patch(path string, handler Handler)
- func (b *Blade) Post(path string, handler Handler)
- func (b *Blade) Put(path string, handler Handler)
- func (b *Blade) Router() *Router
- func (b *Blade) Run(addr ...string) error
- func (b *Blade) RunServer(server *http.Server, l net.Listener) error
- func (b *Blade) RunTLS(addr, certFile, keyFile string) error
- func (b *Blade) RunUnix(file string) error
- func (b *Blade) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (b *Blade) Server() *http.Server
- func (b *Blade) SetGzip(gzip bool)
- func (b *Blade) SetSignAutoRun(auto bool)
- func (b *Blade) Shutdown() error
- func (b *Blade) Static(path, bind string)
- func (b *Blade) Use(middlewares ...Middleware)
- type Context
- func (c *Context) B() *Blade
- func (c *Context) Bind(obj interface{}) error
- func (c *Context) Bytes(body []byte) error
- func (c *Context) CSS(text string) error
- func (c *Context) ClientIP() string
- func (c *Context) Close()
- func (c *Context) Cookie(name string) (string, error)
- func (c *Context) Error(statusCode int, errorList ...interface{}) error
- func (c *Context) File(file string) error
- func (c *Context) Get(param string) string
- func (c *Context) GetInt(param string) (int, error)
- func (c *Context) GetKey(key string) (value interface{}, exists bool)
- func (c *Context) GetKeyBodyJsonAny(key string) (sm interface{})
- func (c *Context) GetKeyBool(key string) (b bool)
- func (c *Context) GetKeyByte(key string) (s []byte)
- func (c *Context) GetKeyDuration(key string) (d time.Duration)
- func (c *Context) GetKeyFloat64(key string) (f64 float64)
- func (c *Context) GetKeyInt(key string) (i int)
- func (c *Context) GetKeyInt64(key string) (i64 int64)
- func (c *Context) GetKeyString(key string) (s string)
- func (c *Context) GetKeyStringMap(key string) (sm map[string]interface{})
- func (c *Context) GetKeyStringMapString(key string) (sms map[string]string)
- func (c *Context) GetKeyStringSlice(key string) (ss []string)
- func (c *Context) GetKeyTime(key string) (t time.Time)
- func (c *Context) HTML(html string) error
- func (c *Context) IP() string
- func (c *Context) JSON(value interface{}) error
- func (c *Context) JSONAndStatus(status int, value interface{}) error
- func (c *Context) JavaScript(code string) error
- func (c *Context) MustBindWith(obj interface{}, b binding.Binding) error
- func (c *Context) Path() string
- func (c *Context) Query(param string) string
- func (c *Context) ReadAll(reader io.Reader) error
- func (c *Context) ReadSeeker(reader io.ReadSeeker) error
- func (c *Context) Reader(reader io.Reader) error
- func (c *Context) Redirect(status int, u string) error
- func (c *Context) Request() Request
- func (c *Context) Response() Response
- func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (c *Context) SetKey(key string, value interface{})
- func (c *Context) SetPath(path string)
- func (c *Context) SetSameSite(samesite http.SameSite)
- func (c *Context) SetStatus(status int)
- func (c *Context) ShouldBind(obj interface{}) error
- func (c *Context) ShouldBindJSON(obj interface{}) error
- func (c *Context) ShouldBindQuery(obj interface{}) error
- func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error
- func (c *Context) Status() int
- func (c *Context) String(body string) error
- func (c *Context) Text(text string) error
- type H
- type Handler
- type Middleware
- type Request
- type Response
- type Router
Constants ¶
const (
BodyBytesKey = "hblade_bodybyteskey"
)
const LogKey = "hblade_log_key"
Variables ¶
var Json = jsoniter.ConfigCompatibleWithStandardLibrary
var Log *zap.Logger = initLog()
Functions ¶
func LogReleaseCtr ¶
func LogWithCtr ¶
Types ¶
type Blade ¶
type Blade struct {
// contains filtered or unexported fields
}
func (*Blade) Delete ¶
Delete registers your function to be called when the given DELETE path has been requested.
func (*Blade) Get ¶
Get registers your function to be called when the given GET path has been requested.
func (*Blade) Head ¶
Head registers your function to be called when the given HEAD path has been requested.
func (*Blade) OnEnd ¶
func (b *Blade) OnEnd(callback func())
OnEnd registers a callback to be executed on server shutdown.
func (*Blade) OnStart ¶
func (b *Blade) OnStart(callback func())
OnStart registers a callback to be executed on server start.
func (*Blade) Options ¶
Options registers your function to be called when the given OPTIONS path has been requested.
func (*Blade) Patch ¶
Patch registers your function to be called when the given PATCH path has been requested.
func (*Blade) Post ¶
Post registers your function to be called when the given POST path has been requested.
func (*Blade) Put ¶
Put registers your function to be called when the given PUT path has been requested.
func (*Blade) ServeHTTP ¶
func (b *Blade) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServeHTTP responds to the given request.
func (*Blade) SetSignAutoRun ¶
func (*Blade) Use ¶
func (b *Blade) Use(middlewares ...Middleware)
Use adds middleware to your middleware chain.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents a request & response context.
func (*Context) Bind ¶
Bind checks the Content-Type to select a binding engine automatically, Depending the "Content-Type" header different bindings are used:
"application/json" --> JSON binding "application/xml" --> XML binding
otherwise --> returns an error. It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input. It decodes the json payload into the struct specified as a pointer. It writes a 400 error and sets Content-Type header "text/plain" in the response if input is not valid.
func (*Context) Close ¶
func (c *Context) Close()
Close frees up resources and is automatically called in the ServeHTTP part of the web server.
func (*Context) File ¶
File sends the contents of a local file and determines its mime type by extension.
func (*Context) GetKey ¶
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
func (*Context) GetKeyBodyJsonAny ¶
func (*Context) GetKeyBool ¶
func (*Context) GetKeyByte ¶
func (*Context) GetKeyFloat64 ¶
func (*Context) GetKeyInt64 ¶
func (*Context) GetKeyString ¶
func (*Context) GetKeyStringMap ¶
func (*Context) GetKeyStringMapString ¶
func (*Context) GetKeyStringSlice ¶
func (*Context) JSONAndStatus ¶
func (*Context) JavaScript ¶
JavaScript sends a script.
func (*Context) MustBindWith ¶
MustBindWith binds the passed struct pointer using the specified binding engine. It will abort the request with HTTP 400 if any error occurs. See the binding package.
func (*Context) ReadAll ¶
ReadAll returns the contents of the reader. This will create an in-memory copy and calculate the E-Tag before sending the data. Compression will be applied if necessary.
func (*Context) ReadSeeker ¶
func (c *Context) ReadSeeker(reader io.ReadSeeker) error
发送io.ReadSeeker内容,不会压缩 如阅读器包含大量数据时用此功能
func (*Context) SetCookie ¶
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
SetCookie adds a Set-Cookie header to the ResponseWriter's headers.
func (*Context) SetKey ¶
Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.Keys if it was not used previously.
func (*Context) SetSameSite ¶
SetSameSite with cookie
func (*Context) ShouldBind ¶
func (*Context) ShouldBindJSON ¶
ShouldBindJSON is a shortcut for c.ShouldBindWith(obj, binding.JSON).
func (*Context) ShouldBindQuery ¶
ShouldBindQuery is a shortcut for c.ShouldBindWith(obj, binding.Query).
func (*Context) ShouldBindWith ¶
ShouldBindWith binds the passed struct pointer using the specified binding engine. See the binding package.
type Middleware ¶
Middleware is a function that accepts a handler and transforms it into a different handler.
func Recovery ¶
func Recovery() Middleware
Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.
type Response ¶
type Response interface { Header(string) string Rw() http.ResponseWriter SetHeader(string, string) SetRw(http.ResponseWriter) Pusher() http.Pusher }
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is a high-performance router.