Documentation
¶
Index ¶
- Variables
- func FileServer(r Router, path string, fs fs.FS)
- type Context
- func (c *Context) BindForm(obj any) error
- func (c *Context) BindHeader(obj any) error
- func (c *Context) BindJSON(obj any) error
- func (c *Context) BindMultiForm(obj any) error
- func (c *Context) BindPostForm(obj any) error
- func (c *Context) BindQuery(obj any) error
- func (c *Context) BindXML(obj any) error
- func (c *Context) Context() context.Context
- func (c *Context) Deadline() (deadline time.Time, ok bool)
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) GetContentType() string
- func (c *Context) GetHeader(key string) config.Value
- func (c *Context) GetHeaders(key string) []string
- func (c *Context) GetParam(key string) config.Value
- func (c *Context) GetParams() map[string]string
- func (c *Context) GetQueries(key string) []string
- func (c *Context) GetQuery(key string) config.Value
- func (c *Context) GetRawBody() ([]byte, error)
- func (c *Context) GetRoutePattern() string
- func (c *Context) HTML(status int, tpl template.Template, data any, name ...string) error
- func (c *Context) Header(key, value string)
- func (c *Context) JSON(status int, v any) error
- func (c *Context) MustGetRawBody() []byte
- func (c *Context) Redirect(status int, url string)
- func (c *Context) Render(status int, contentType string, bs []byte) error
- func (c *Context) Status(status int)
- func (c *Context) TEXT(status int, text string) error
- func (c *Context) Value(key any) any
- func (c *Context) XML(status int, v any) error
- type Handler
- type HandlerCtx
- type HandlerFunc
- type Middleware
- type Mux
- func (m *Mux) Group(fn RouterFunc) Router
- func (m *Mux) Handle(pattern string, h Handler)
- func (m *Mux) HandleCtx(pattern string, h HandlerCtx)
- func (m *Mux) HandleFunc(pattern string, h HandlerFunc)
- func (m *Mux) Mount(pattern string, h Handler)
- func (m *Mux) Route(pattern string, fn RouterFunc) Router
- func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Mux) Use(middlewares ...Middleware)
- func (m *Mux) With(middlewares ...Middleware) Router
- type Request
- type ResponseWriter
- type Router
- type RouterFunc
- type Server
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrorHandler = func(c *Context, err error) { if err == nil { return } e := ierr.FromError(err) _ = c.JSON(e.Status(), e) }
View Source
var PanicHandler = func(c *Context, rec any) { if rec == nil { return } slog.Error("[%s] %v", osutil.CallerString(3), rec, slog.String("stack", osutil.Stack(2)), slog.GetAttrs(c)) err, ok := rec.(error) if !ok { err = fmt.Errorf("%v", rec) } ErrorHandler(c, err) }
View Source
var StripPrefix = http.StripPrefix
Functions ¶
Types ¶
type Context ¶
type Context struct { Req *Request Res ResponseWriter // contains filtered or unexported fields }
func NewContext ¶
func NewContext(w ResponseWriter, r *Request) *Context
func (*Context) BindHeader ¶
func (*Context) BindMultiForm ¶
func (*Context) BindPostForm ¶
func (*Context) GetContentType ¶
func (*Context) GetHeaders ¶
func (*Context) GetQueries ¶
func (*Context) GetRawBody ¶
func (*Context) GetRoutePattern ¶
func (*Context) MustGetRawBody ¶
type HandlerCtx ¶
func (HandlerCtx) ServeHTTP ¶
func (hc HandlerCtx) ServeHTTP(w ResponseWriter, r *Request)
type HandlerFunc ¶
type HandlerFunc = http.HandlerFunc
type Middleware ¶
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
func (*Mux) Group ¶
func (m *Mux) Group(fn RouterFunc) Router
func (*Mux) HandleCtx ¶
func (m *Mux) HandleCtx(pattern string, h HandlerCtx)
func (*Mux) HandleFunc ¶
func (m *Mux) HandleFunc(pattern string, h HandlerFunc)
func (*Mux) Use ¶
func (m *Mux) Use(middlewares ...Middleware)
func (*Mux) With ¶
func (m *Mux) With(middlewares ...Middleware) Router
type ResponseWriter ¶
type ResponseWriter = http.ResponseWriter
type Router ¶
type Router interface { Handler Use(middlewares ...Middleware) With(middlewares ...Middleware) Router Group(fn RouterFunc) Router Route(pattern string, fn RouterFunc) Router Mount(pattern string, h Handler) Handle(pattern string, h Handler) HandleFunc(pattern string, h HandlerFunc) HandleCtx(pattern string, h HandlerCtx) }
type RouterFunc ¶
type RouterFunc = func(r Router)
Click to show internal directories.
Click to hide internal directories.