http

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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 NewCtx

func NewCtx(w http.ResponseWriter, r *http.Request, params ...Param) *Ctx

func (*Ctx) Bind

func (c *Ctx) Bind(v any) error

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) Body

func (c *Ctx) Body() ([]byte, error)

func (*Ctx) Bytes

func (c *Ctx) Bytes(status int, contentType string, bytes []byte) error

Bytes writes raw bytes with the specified content-type.

func (*Ctx) File

func (c *Ctx) File(path string) error

File serves a file at the given filesystem path. This single-argument version matches echo's ctx.File(path) signature.

func (*Ctx) FormValue

func (c *Ctx) FormValue(key string) string

FormValue returns the form value (both URL-encoded and multipart).

func (*Ctx) Get

func (c *Ctx) Get(key string) any

Get retrieves a value from the request-scoped context store.

func (*Ctx) HTML

func (c *Ctx) HTML(status int, s string) error

HTML is an alias for Html, matching echo's API.

func (*Ctx) Html

func (c *Ctx) Html(status int, s string) error

Html writes an HTML response.

func (*Ctx) JSON

func (c *Ctx) JSON(status int, data any) error

JSON writes a JSON response with the given status code.

func (*Ctx) MultipartForm

func (c *Ctx) MultipartForm() (*multipart.Form, error)

MultipartForm parses and returns the multipart form data.

func (*Ctx) Next

func (c *Ctx) Next()

func (*Ctx) NoContent

func (c *Ctx) NoContent(status int) error

NoContent sends a response with no body.

func (*Ctx) Param

func (c *Ctx) Param(key string) string

func (*Ctx) Params

func (c *Ctx) Params() []Param

func (*Ctx) Query

func (c *Ctx) Query(key string) string

Query returns the URL query parameter by key.

func (*Ctx) QueryParam

func (c *Ctx) QueryParam(key string) string

QueryParam is an alias for Query, matching echo's API.

func (*Ctx) Redirect

func (c *Ctx) Redirect(status int, url string) error

Redirect performs an HTTP redirect.

func (*Ctx) Render

func (c *Ctx) Render(status int, name string, data any) error

Render renders a named template using the registered renderer.

func (*Ctx) Request

func (c *Ctx) Request() *http.Request

func (*Ctx) Response

func (c *Ctx) Response() *Response

Response returns the response wrapper which tracks Committed state.

func (*Ctx) ServeFile

func (c *Ctx) ServeFile(status int, path string) error

ServeFile serves a file with an explicit status code (weed's original API).

func (*Ctx) Set

func (c *Ctx) Set(key string, val any)

Set stores a value in the request-scoped context store.

func (*Ctx) SetRenderer

func (c *Ctx) SetRenderer(r Renderer)

SetRenderer sets the template renderer for this context.

func (*Ctx) String

func (c *Ctx) String(status int, s string) error

String is an alias for Text, matching echo's API.

func (*Ctx) Text

func (c *Ctx) Text(status int, s string) error

Text writes a plain text response.

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

func NewHTTPError(code int, message ...interface{}) *HTTPError

NewHTTPError creates a new HTTPError.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type HandlerFunc

type HandlerFunc func(ctx *Ctx) error

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 Param

type Param = radix.Param

Param is an alias for radix.Param so existing code can use http.Param.

type Params

type Params = radix.Params

Params is an alias for radix.Params so existing code can use http.Params.

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) Header

func (r *Response) Header() http.Header

func (*Response) Write

func (r *Response) Write(b []byte) (int, error)

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

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 NewRouter

func NewRouter() *Router

NewRouter creates a new Router.

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

func (r *Router) SetRenderer(renderer Renderer)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL