koa

package
v0.0.0-...-bb95748 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KOA_EVENT_ERROR = "error" // 发生错误
	KOA_EVENT_CLOSE = "close" // 应用关闭
)

Variables

This section is empty.

Functions

func Assert

func Assert(err error, msg string)

Types

type Context

type Context struct {
	Req      *http.Request
	Res      http.ResponseWriter
	Request  *KoaRequest
	Response *KoaResponse
	Cookies  *koaCookies
	State    map[string]any
	// contains filtered or unexported fields
}

* 应用上下文,存储例如db,request等数据

func (*Context) Assert

func (this *Context) Assert(state bool, code int)

func (*Context) Throw

func (this *Context) Throw(code int)

type Koa

type Koa struct {
	// contains filtered or unexported fields
}

func NewKoa

func NewKoa(config *KoaConfig) *Koa

func (*Koa) Emit

func (this *Koa) Emit(event string, args ...any)

func (*Koa) Listen

func (this *Koa) Listen(port int)

func (*Koa) On

func (this *Koa) On(event string, handler func(arg ...any))

func (*Koa) Use

func (this *Koa) Use(plugin Plugin)

type KoaConfig

type KoaConfig struct {
	// contains filtered or unexported fields
}

func NewKoaConfig

func NewKoaConfig() *KoaConfig

type KoaRequest

type KoaRequest struct {
	Body any
}

type KoaResponse

type KoaResponse struct {
	Body any
	// contains filtered or unexported fields
}

func (*KoaResponse) GetStatus

func (this *KoaResponse) GetStatus() int

func (*KoaResponse) Header

func (this *KoaResponse) Header() http.Header

func (*KoaResponse) SetStatus

func (this *KoaResponse) SetStatus(status int)

func (*KoaResponse) Write

func (this *KoaResponse) Write(bytes []byte) error

type Plugin

type Plugin interface {
	Call(ctx *Context)
}

type PluginMultiArg

type PluginMultiArg func(ctx *Context, next func())

func (PluginMultiArg) Call

func (this PluginMultiArg) Call(ctx *Context)

type PluginSingleArg

type PluginSingleArg func(ctx *Context)

func (PluginSingleArg) Call

func (this PluginSingleArg) Call(ctx *Context)

Jump to

Keyboard shortcuts

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