Documentation
¶
Index ¶
- Variables
- func ErrorFormatJSON(err error) map[string]any
- func GetRequestCtxKey() requestKey
- func ToHTTPHandler(h Handler) http.Handler
- type Context
- func (c *Context) AllCookies() []*http.Cookie
- func (c *Context) Body() io.ReadCloser
- func (c *Context) BodyParser(v any) error
- func (c *Context) ClearCookie(key string)
- func (c *Context) Flush()
- func (c *Context) GetCookie(name string) (*http.Cookie, error)
- func (c *Context) GetHeaders() http.Header
- func (c *Context) JSON(s any) error
- func (c *Context) Next() error
- func (c *Context) ParseBodyInto(v any) error
- func (c *Context) PathParam(key string) string
- func (c *Context) QueryParam(key string) string
- func (c *Context) Request() *http.Request
- func (c *Context) ResponseWriter() http.ResponseWriter
- func (c *Context) SendBytes(b []byte) error
- func (c *Context) SendFile(fp string) error
- func (c *Context) SendHTML(s []byte) error
- func (c *Context) SendJSON(s any) error
- func (c *Context) SendStatus(code int) error
- func (c *Context) SendString(s string) error
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetResponseWriter(rw http.ResponseWriter)
- func (c *Context) Status(code int) *Context
- func (c *Context) URL() *url.URL
- func (c *Context) Write(p []byte) (n int, err error)
- func (c *Context) Writer() io.Writer
- type ErrorHandler
- type Handler
- type KV
- type Router
- func (r *Router) Delete(path string, handlers ...Handler)
- func (r *Router) Get(path string, handlers ...Handler)
- func (r *Router) Handle(path string, handler http.Handler)
- func (r *Router) HandleFunc(path string, handle http.HandlerFunc)
- func (r *Router) Head(path string, handlers ...Handler)
- func (r *Router) Method(method string, path string, handlers ...Handler)
- func (r *Router) Mount(path string, h http.Handler)
- func (r *Router) Post(path string, handlers ...Handler)
- func (r *Router) Put(path string, handlers ...Handler)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(handlers ...Handler)
Constants ¶
This section is empty.
Variables ¶
var ( // JSONEncoder defaults to [encoding/json.Marshal](https://pkg.go.dev/encoding/json#Marshal) JSONEncoder func(v any) ([]byte, error) = json.Marshal // JSONDecoder defaults to [encoding/json.Unmarshal](https://pkg.go.dev/encoding/json#Unmarshal) JSONDecoder func(b []byte, v any) error = json.Unmarshal )
Package level variables, it mainly just introduces a constraint that there will be same encoders across the package in an application lifecycle
Functions ¶
func ErrorFormatJSON ¶
func GetRequestCtxKey ¶
func GetRequestCtxKey() requestKey
func ToHTTPHandler ¶
Types ¶
type Context ¶
type Context struct { // Alias to request.Context() // It allows user to pass Context in place of context.Context context.Context // per-request key value store KV *KV // contains filtered or unexported fields }
func NewContext ¶
func NewContext(r *http.Request, w http.ResponseWriter) *Context
func (*Context) AllCookies ¶
func (*Context) Body ¶
func (c *Context) Body() io.ReadCloser
func (*Context) BodyParser ¶
BodyParser is alias for ParseBodyInto
func (*Context) ClearCookie ¶
func (*Context) GetHeaders ¶
GetHeaders() is http request headers
func (*Context) ParseBodyInto ¶
func (*Context) QueryParam ¶
QueryParam is like this `id` in this route path `/resource?id=hello-world`
func (*Context) Request ¶
Request() returns original http request for feature parity, until ivy gets a rigid API design
func (*Context) ResponseWriter ¶
func (c *Context) ResponseWriter() http.ResponseWriter
ResponseWriter() returns original http response writer for feature parity, until ivy gets a rigid API design
func (*Context) SendStatus ¶
func (*Context) SendString ¶
func (*Context) SetResponseWriter ¶
func (c *Context) SetResponseWriter(rw http.ResponseWriter)
func (*Context) Status ¶
Status(int) let's you set status codes for your responses use it like `c.Status(201).SendString("OK")`
type ErrorHandler ¶
var DefaultErrorHandler ErrorHandler = func(c *Context, err error) { http.Error(c.ResponseWriter(), err.Error(), http.StatusInternalServerError) }
type Handler ¶
func ToIvyHandler ¶
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
func (*KV) Get ¶
Get fetches the value of key in request level KV store in case, key is not present default value is returned
type Router ¶
type Router struct { ErrorHandler ErrorHandler // contains filtered or unexported fields }
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(path string, handle http.HandlerFunc)