Documentation ¶
Index ¶
- Variables
- type Cookie
- type Ctx
- func (c *Ctx) BodyParser(d any) error
- func (c *Ctx) Context() context.Context
- func (c *Ctx) Cookie(key string, defVal ...string) string
- func (c *Ctx) FormValue(key string, def ...string) string
- func (c *Ctx) FormValues(key string, def ...string) []string
- func (c *Ctx) Get(header string, def ...string) string
- func (c *Ctx) Hijack(fn HijackerFunc) error
- func (c *Ctx) IP() string
- func (c *Ctx) Method() string
- func (c *Ctx) Next() error
- func (c *Ctx) Param(name string) string
- func (c *Ctx) Params() map[string]string
- func (c *Ctx) Path() string
- func (c *Ctx) Queries(key string) []string
- func (c *Ctx) Query(key string, def ...string) string
- func (c *Ctx) ReadFrom(content io.Reader) error
- func (c *Ctx) Redirect(loc string, code ...int) error
- func (c *Ctx) Reset()
- func (c *Ctx) SendFile(path string) error
- func (c *Ctx) SendStatus(code int) error
- func (c *Ctx) SendString(d string) error
- func (c *Ctx) Set(key, val string) *Ctx
- func (c *Ctx) SetCookie(key, val string, ck ...Cookie) *Ctx
- func (c *Ctx) Status(code int) *Ctx
- func (c *Ctx) URL() *url.URL
- func (c *Ctx) Write(d []byte) (int, error)
- type Handler
- func (h *Handler) Get(path string, fn func(*Ctx) error) error
- func (h *Handler) Method(method, path string, fn func(*Ctx) error) error
- func (h *Handler) Post(path string, fn func(*Ctx) error) error
- func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Use(fn func(*Ctx) error) error
- type HijackerFunc
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
Ctx is the contextual object of mwr that provides all data one may want to know for a HTTP request.
Ctx should not be used after the end of a handler, nor after the HTTP response has been sent out.
func (*Ctx) BodyParser ¶
BodyParser parses the body contents according to the Content-Type. BodyParser supports JSON.
If Content-Type is blank, ErrNoData is returned. If the Content-Type specifies an unsupported format, ErrUnsupported is returned. Otherwise, an error from the appropriate parser may be returned.
func (*Ctx) Cookie ¶
Cookie returns the value of the cookie specified by key.
By default, Cookie will return "" if the cookie is not found, however if a default value is specified then that will be returned.
func (*Ctx) FormValue ¶
FormValue gets the value of a form on a POST or a PUT request.
TODO: def is not implemented. Do not use it.
func (*Ctx) FormValues ¶
FormValues returns all values for any given key.
func (*Ctx) Get ¶
Get returns the value of the request header, or a default value.
func (*Ctx) Hijack ¶
func (c *Ctx) Hijack(fn HijackerFunc) error
Hijack hijacks the HTTP portion of this connection after all handlers are run. No data will be sent to the client after Hijack is called.
func (*Ctx) Next ¶
Next recurses into the next handler and returns the error from it.
This method will never fail unless the request is finished.
func (*Ctx) Param ¶
Param returns a parameter from the path, or an empty string.
The returned value may not be used once the request is completed.
func (*Ctx) Params ¶
Params returns all parameters specified in the request by their name.
The returned map may not be used once the request is completed.
func (*Ctx) Queries ¶
Queries returns a list of query values.
func (*Ctx) Query ¶
Query returns the value of a query value, or a default value.
func (*Ctx) ReadFrom ¶
ReadFrom copies all data from an io.Reader to a client.
The Ctx will be unable to send any more data after calling ReadFrom. All calls to functions that would write data will panic.
func (*Ctx) Redirect ¶
Redirect a client to another page.
This method will panic if the request is finished.
func (*Ctx) SendFile ¶
SendFile sends a file to the end user. Unlike all other functions, this completely bypasses the internal buffer.
This method will never fail as this uses http.ServeFile internally which does not return an error.
The Ctx will be unable to send any more data after calling SendFile. All calls to functions that would write data will panic.
func (*Ctx) SendStatus ¶
SendStatus sends headers and a status code to the client.
This method will panic if the request is finished.
func (*Ctx) SendString ¶
SendString is a convenience wrapper around Write.
This method will never fail unless the request is finished.
func (*Ctx) Set ¶
Set sets the value of a response header.
This method is chainable. This method will panic if the request is finished.
func (*Ctx) SetCookie ¶
SetCookie sets the value of a cookie.
By default, the cookie will have SameSite=Strict, and will not expire. However if a Cookie is passed as an argument, values will be copied from the Cookie. Name and Value will be filled from key and val.
If val is empty, the cookie will be unset.
func (*Ctx) Status ¶
Status sets the status code for the reply to the client.
This method is chainable. This method will panic if the request is finished.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a net/http.Handler interface that serves as the way you would expose mwr to the web.
func (*Handler) Get ¶
Get pushes a handler for a GET route onto the handler stack.
func (*Handler) Method ¶
Method creates a route that matches a method and a path and pushes it onto the Handler stack.
Use an empty method value to match all methods.
func (*Handler) Post ¶
Post pushes a handler for a POST route onto the handler stack.
type HijackerFunc ¶
type HijackerFunc func(http.ResponseWriter, *http.Request)
HijackerFunc takes over the HTTP connection.