router

package
v0.12.7 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext[P any, D any](params P, data D) context.Context

创建默认上下文

Types

type ActionAuth

type ActionAuth func(ctx context.Context) error

type ActionCallback

type ActionCallback func(ctx context.Context) (any, error)

type Context

type Context[P, D any] struct {
	Params P
	Data   D
}

默认 context value 结构

type ContextKeyType

type ContextKeyType string
const ContextKey ContextKeyType = "ctxdata"

默认上下文key

type Error

type Error struct {
	Code int
	Msg  string
}

func (Error) Error

func (t Error) Error() string

type Router

type Router[P any] struct {
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter[T any]() *Router[T]

func (*Router[P]) Invoke

func (t *Router[P]) Invoke(ctx context.Context, actionName string) (any, error)

调用路由

func (*Router[P]) On

func (t *Router[P]) On(actionName string, callback ActionCallback, auths ...ActionAuth)

注册路由

func (*Router[P]) Validate added in v0.12.2

func (t *Router[P]) Validate(ctx context.Context, req any) (*Context[P, any], error)

校验并解析参数

Jump to

Keyboard shortcuts

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