Documentation
¶
Index ¶
- type Ctx
- func (c *Ctx) Bind(v any) error
- func (c *Ctx) Body() ([]byte, error)
- func (c *Ctx) Bytes(status int, contentType string, bytes []byte) error
- func (c *Ctx) File(path string) error
- func (c *Ctx) FormValue(key string) string
- func (c *Ctx) Get(key string) any
- func (c *Ctx) HTML(status int, s string) error
- func (c *Ctx) Html(status int, s string) error
- func (c *Ctx) JSON(status int, data any) error
- func (c *Ctx) MultipartForm() (*multipart.Form, error)
- func (c *Ctx) Next()
- func (c *Ctx) NoContent(status int) error
- func (c *Ctx) Param(key string) string
- func (c *Ctx) Params() []Param
- func (c *Ctx) Query(key string) string
- func (c *Ctx) QueryParam(key string) string
- func (c *Ctx) Redirect(status int, url string) error
- func (c *Ctx) Render(status int, name string, data any) error
- func (c *Ctx) Request() *http.Request
- func (c *Ctx) Response() *Response
- func (c *Ctx) ServeFile(status int, path string) error
- func (c *Ctx) Set(key string, val any)
- func (c *Ctx) SetRenderer(r Renderer)
- func (c *Ctx) String(status int, s string) error
- func (c *Ctx) Text(status int, s string) error
- func (c *Ctx) Writer() http.ResponseWriter
- type HTTPError
- type HandlerFunc
- type MiddlewareFunc
- type Param
- type Params
- type Renderer
- type Response
- type Router
- type RouterGroup
- func (g *RouterGroup) DELETE(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouterGroup) GET(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouterGroup) Group(prefix string, middlewares ...MiddlewareFunc) *RouterGroup
- func (g *RouterGroup) Handle(method string, path string, handler HandlerFunc, mw ...MiddlewareFunc)
- func (g *RouterGroup) POST(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouterGroup) PUT(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
- func (g *RouterGroup) Prefix() string
- func (g *RouterGroup) Static(prefix string, root string)
- func (g *RouterGroup) Use(middlewares ...MiddlewareFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
func (*Ctx) Bind ¶
Bind decodes the request body (JSON) into v. If Content-Type is multipart/form or application/x-www-form-urlencoded, it falls back to form parsing and fills v via reflection (basic).
func (*Ctx) File ¶
File serves a file at the given filesystem path. This single-argument version matches echo's ctx.File(path) signature.
func (*Ctx) MultipartForm ¶
MultipartForm parses and returns the multipart form data.
func (*Ctx) QueryParam ¶
QueryParam is an alias for Query, matching echo's API.
func (*Ctx) SetRenderer ¶
SetRenderer sets the template renderer for this context.
func (*Ctx) Writer ¶
func (c *Ctx) Writer() http.ResponseWriter
type HTTPError ¶
type HTTPError struct {
Code int
Message interface{}
}
HTTPError represents an HTTP error with a status code and message. It mirrors echo.HTTPError so ocypode's error-handling middleware works as-is.
func NewHTTPError ¶
NewHTTPError creates a new HTTPError.
type HandlerFunc ¶
HandlerFunc is a custom handler that includes URL parameters. IMPORTANT NOTE: To achieve "Zero Allocation", the `ctx` variable is fetched from sync.Pool. The lifecycle of `ctx` is only valid while this function is running. DO NOT pass `ctx` to another Goroutine. If needed, please copy it.
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
type Renderer ¶
type Renderer interface {
// Render writes the rendered template to w.
// name is the template name, data is the template data, c is the request context.
Render(w io.Writer, name string, data interface{}, c *Ctx) error
}
Renderer is the interface that wraps the Render method. It mirrors echo's Renderer interface so existing renderers can be adapted.
type Response ¶
type Response struct {
Writer http.ResponseWriter
Committed bool
Status int
}
Response is a thin wrapper around http.ResponseWriter that tracks whether the response header has already been written (Committed). This mirrors the echo.Response type used by ocypode's middleware.
func (*Response) WriteHeader ¶
type Router ¶
type Router struct {
*RouterGroup
// contains filtered or unexported fields
}
Router is an HTTP routing multiplexer optimized for high concurrency and low RAM usage.
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP makes the Router implement the http.Handler interface.
func (*Router) SetRenderer ¶
SetRenderer sets the template renderer used for all Ctx.Render() calls.
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup represents a group of routes that share a common prefix and middlewares.
func (*RouterGroup) DELETE ¶
func (g *RouterGroup) DELETE(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
DELETE is a shortcut for Handle(http.MethodDelete, path, handler)
func (*RouterGroup) GET ¶
func (g *RouterGroup) GET(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
GET is a shortcut for Handle(http.MethodGet, path, handler)
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(prefix string, middlewares ...MiddlewareFunc) *RouterGroup
Group creates a new RouterGroup with the given prefix and middlewares.
func (*RouterGroup) Handle ¶
func (g *RouterGroup) Handle(method string, path string, handler HandlerFunc, mw ...MiddlewareFunc)
Handle registers a new request handler with the given path and method.
func (*RouterGroup) POST ¶
func (g *RouterGroup) POST(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
POST is a shortcut for Handle(http.MethodPost, path, handler)
func (*RouterGroup) PUT ¶
func (g *RouterGroup) PUT(path string, handler HandlerFunc, middlewares ...MiddlewareFunc)
PUT is a shortcut for Handle(http.MethodPut, path, handler)
func (*RouterGroup) Prefix ¶
func (g *RouterGroup) Prefix() string
Prefix returns the full accumulated prefix of this group.
func (*RouterGroup) Static ¶
func (g *RouterGroup) Static(prefix string, root string)
func (*RouterGroup) Use ¶
func (g *RouterGroup) Use(middlewares ...MiddlewareFunc)
Use adds middlewares to the group.