geezer/hook.go

49 lines
822 B
Go
Raw Permalink Normal View History

2022-02-06 22:33:02 +03:00
package geezer
import "github.com/neonxp/geezer/render"
//go:generate stringer -type=HookLifecycle,HookType -output hook_string.go
type HookLifecycle int
const (
HookBefore HookLifecycle = iota
HookAfter
HookError
)
type HookType int
const (
HookAll HookType = iota
HookFind
HookGet
HookCreate
HookUpdate
HookPatch
HookRemove
)
var hookTypeFromMethod = map[Method]HookType{
MethodFind: HookFind,
MethodGet: HookGet,
MethodCreate: HookCreate,
MethodUpdate: HookUpdate,
MethodPatch: HookPatch,
MethodRemove: HookRemove,
}
type HookContext struct {
2022-02-08 02:14:57 +03:00
App AppKernel
2022-02-06 22:33:02 +03:00
Path []string
Method Method
Type HookLifecycle
ID string
Params Params
Data Data
Err error
Result render.Renderer
StatusCode int
}
type Hook func(ctx *HookContext) error