Documentation ¶
Index ¶
- Variables
- func Delete(path string, fun RouterHandlerFunc)
- func Get(path string, fun RouterHandlerFunc)
- func Head(path string, fun RouterHandlerFunc)
- func Options(path string, fun RouterHandlerFunc)
- func Patch(path string, fun RouterHandlerFunc)
- func Post(path string, fun RouterHandlerFunc)
- func Put(path string, fun RouterHandlerFunc)
- func Trace(path string, fun RouterHandlerFunc)
- func WebSocket(path string, fun RouterHandlerFunc)
- type Context
- type Response
- type RouterHandlerFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrorHandlerFunc = func(ctx *Context, ex *exception.Exception) { ctx.Response.WriteHeader(ex.Code) ctx.Request.Header.Set("Content-Type", "text/plain; charset=utf-8") ctx.Request.Header.Set("X-Content-Type-Options", "nosniff") _, err := ctx.Response.Write(util.StringToByteArray(ex.Error())) if err != nil { ctx.Logger.Warn(err.Error()) } ctx.Response.Flush() }
错误处理方法
View Source
var NotFoundHandlerFunc = func(ctx *Context) { ctx.Response.WriteHeader(http.StatusNotFound) ctx.Request.Header.Set("Content-Type", "text/plain; charset=utf-8") ctx.Request.Header.Set("X-Content-Type-Options", "nosniff") _, err := ctx.Response.Write(util.StringToByteArray(http.StatusText(http.StatusNotFound))) if err != nil { ctx.Logger.Warn(err.Error()) } ctx.Response.Flush() }
404处理方法
Functions ¶
func Delete ¶
func Delete(path string, fun RouterHandlerFunc)
func Get ¶
func Get(path string, fun RouterHandlerFunc)
func Head ¶
func Head(path string, fun RouterHandlerFunc)
func Options ¶
func Options(path string, fun RouterHandlerFunc)
func Patch ¶
func Patch(path string, fun RouterHandlerFunc)
func Post ¶
func Post(path string, fun RouterHandlerFunc)
func Put ¶
func Put(path string, fun RouterHandlerFunc)
func Trace ¶
func Trace(path string, fun RouterHandlerFunc)
Types ¶
type Context ¶
type Context struct { Request *http.Request Response *Response Websocket *websocket.Conn Store map[string]interface{} Logger *zap.Logger Path string Method string }
请求上下文
func NewContext ¶
type Response ¶
type Response struct { Writer http.ResponseWriter Status int Size int64 Committed bool // contains filtered or unexported fields }
func NewResponse ¶
func NewResponse(w http.ResponseWriter, logger *zap.Logger) (r *Response)
func (*Response) WriteHeader ¶
type RouterHandlerFunc ¶
func Wrapper ¶
func Wrapper(path string) RouterHandlerFunc
Click to show internal directories.
Click to hide internal directories.