koa

package
v2.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: Apache-2.0 Imports: 1 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 {
	Result   Data
	RunCount int
	// contains filtered or unexported fields
}

Context

func NewContext

func NewContext() *Context

New

func (*Context) Abort

func (c *Context) Abort()

Abort prevents pending handlers from being called. Note that this will not stop the current handler. Let's say you have an authorization middleware that validates that the current request is authorized. If the authorization fails (ex: the password does not match), call Abort to ensure the remaining handlers for this request are not called.

func (*Context) Error

func (c *Context) Error(err error)

Error attaches an error to the current context. The error is pushed to a list of errors. It's a good idea to call Error for each error that occurred during the resolution of a request. A middleware can be used to collect all the errors and push them to a database together, print a log, or append it in the HTTP response. Error will panic if err is nil.

func (*Context) IsAborted

func (c *Context) IsAborted() bool

IsAborted returns true if the current context was aborted.

func (*Context) Next

func (c *Context) Next()

Next should be used only inside middleware. It executes the pending handlers in the chain inside the calling handler. See example in GitHub.

func (*Context) Run

func (c *Context) Run() *Context

Run from the first position of the context

func (*Context) Use

func (c *Context) Use(middleware ...HandlerFunc) *Context

Use attaches a global middleware to the router. ie. the middleware attached though Use() will be For example, this is the right place for a logger or error management middleware.

type Data

type Data struct {
	Err  error       `json:"err,omitempty"`
	Data interface{} `json:"data"`
}

Context Data

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc defines the handler used by gin middleware as return value.

type HandlersChain

type HandlersChain []HandlerFunc

HandlersChain defines a HandlerFunc array.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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