context

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Writer  http.ResponseWriter
	Request *http.Request

	// Handlers is the middleware chain for this request
	Handlers []HandlerFunc

	// Params are the route parameters
	Params router.Params

	// Keys is a key/value pair exclusively for the context of each request.
	Keys map[string]interface{}

	// Templates holds the parsed templates (injected by Engine)
	Templates *template.Template
	// contains filtered or unexported fields
}

Context is the context for the current request. It wraps http.ResponseWriter and *http.Request and adds helper methods.

func New

New creates a new Context.

func (*Context) Bind added in v0.1.3

func (c *Context) Bind(obj interface{}) error

Bind decodes the request body into obj and validates it. Currently supports JSON.

func (*Context) File added in v0.1.3

func (c *Context) File(filepath string)

File writes the specified file into the body stream in an efficient way.

func (*Context) FormFile added in v0.1.3

func (c *Context) FormFile(name string) (*multipart.FileHeader, error)

FormFile returns the first file for the provided form key.

func (*Context) Get added in v0.1.3

func (c *Context) Get(key string) (value interface{}, exists bool)

Get returns the value for the given key, ie: (value, true). If the value does not exist it returns (nil, false)

func (*Context) HTML added in v0.1.3

func (c *Context) HTML(code int, html string) error

HTML sends an HTML response (Raw String).

func (*Context) HeaderWritten added in v1.0.0

func (c *Context) HeaderWritten() bool

HeaderWritten reports whether the response headers have been sent. Used by middleware (e.g. Recovery) to avoid writing after response started.

func (*Context) JSON

func (c *Context) JSON(code int, obj interface{}) error

JSON sends a JSON response.

func (*Context) MustGet added in v0.1.3

func (c *Context) MustGet(key string) interface{}

MustGet returns the value for the given key if it exists, otherwise it panics.

func (*Context) Next

func (c *Context) Next()

Next executes the next middleware in the chain. If a handler returns an error and no response has been written yet, a 500 Internal Server Error is sent and the chain is stopped.

func (*Context) Param added in v0.1.3

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

Param returns the value of the URL param.

func (*Context) RenderHTML added in v0.1.3

func (c *Context) RenderHTML(code int, name string, data interface{}) error

RenderHTML renders the template with data and sets values content-type to "text/html".

func (*Context) Reset

func (c *Context) Reset(w http.ResponseWriter, r *http.Request)

Reset re-initializes the context for a new request. Crucial for sync.Pool reuse.

func (*Context) SaveUploadedFile added in v0.1.3

func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error

SaveUploadedFile uploads the form file to specific dst.

func (*Context) Set added in v0.1.3

func (c *Context) Set(key string, value interface{})

Set is used to store a new key/value pair exclusively for this context. It also lazily initializes c.Keys if it was not used previously.

func (*Context) Status

func (c *Context) Status(code int) *Context

Status sets the HTTP status code.

func (*Context) String

func (c *Context) String(code int, format string, values ...interface{}) error

String sends a plain text response.

func (*Context) Upgrade added in v0.1.3

func (c *Context) Upgrade() (*websocket.Conn, error)

Upgrade upgrades the HTTP connection to a WebSocket connection. Returns the *websocket.Conn and any error.

type HandlerFunc

type HandlerFunc func(*Context) error

HandlerFunc matches the KVolt handler signature.

Jump to

Keyboard shortcuts

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