Documentation
¶
Index ¶
- type APIEvent
- type APIResponseEvent
- type App
- type BaseApp
- func (app *BaseApp) Bootstrap() error
- func (app *BaseApp) Config() ConfigInterface
- func (app *BaseApp) DB() *sql.DB
- func (app *BaseApp) DataDir() string
- func (app *BaseApp) IsBootstrapped() bool
- func (app *BaseApp) Logger() LoggerInterface
- func (app *BaseApp) OnAPIRequest() *hook.Hook[*APIEvent]
- func (app *BaseApp) OnAPIResponse() *hook.Hook[*APIResponseEvent]
- func (app *BaseApp) OnBootstrap() *hook.Hook[*BootstrapEvent]
- func (app *BaseApp) OnCategoryCreate() *hook.Hook[*CategoryEvent]
- func (app *BaseApp) OnCustomEvent() *hook.Hook[*CustomEvent]
- func (app *BaseApp) OnReadyResourceAdd() *hook.Hook[*ReadyResourceEvent]
- func (app *BaseApp) OnServe() *hook.Hook[*ServeEvent]
- func (app *BaseApp) OnTagAdd() *hook.Hook[*TagEvent]
- func (app *BaseApp) OnTerminate() *hook.Hook[*TerminateEvent]
- func (app *BaseApp) OnURLAccess() *hook.Hook[*URLAccessEvent]
- func (app *BaseApp) OnURLAdd() *hook.Hook[*URLEvent]
- func (app *BaseApp) OnURLDelete() *hook.Hook[*URLEvent]
- func (app *BaseApp) OnURLUpdate() *hook.Hook[*URLEvent]
- func (app *BaseApp) OnUserLogin() *hook.Hook[*UserEvent]
- func (app *BaseApp) OnUserLogout() *hook.Hook[*UserEvent]
- func (app *BaseApp) OnUserRegister() *hook.Hook[*UserEvent]
- func (app *BaseApp) Restart() error
- func (app *BaseApp) Router() RouterInterface
- func (app *BaseApp) SetConfig(config ConfigInterface)
- func (app *BaseApp) SetDB(db *sql.DB)
- func (app *BaseApp) SetDataDir(dir string)
- func (app *BaseApp) SetLogger(logger LoggerInterface)
- func (app *BaseApp) SetRouter(router RouterInterface)
- func (app *BaseApp) TriggerCustomEvent(name string, data map[string]interface{}) error
- func (app *BaseApp) TriggerReadyResourceAdd(readyResource *entity.ReadyResource, data map[string]interface{}) error
- func (app *BaseApp) TriggerURLAccess(url *entity.Resource, accessLog interface{}, request, response interface{}) error
- func (app *BaseApp) TriggerURLAdd(url *entity.Resource, data map[string]interface{}) error
- func (app *BaseApp) TriggerUserLogin(user *entity.User, data map[string]interface{}) error
- func (app *BaseApp) WithURLDB(fn func(interface{}) error) error
- type BootstrapEvent
- type CategoryEvent
- type ConfigInterface
- type CustomEvent
- type LoggerInterface
- type ReadyResourceEvent
- type RouterInterface
- type ServeEvent
- type TagEvent
- type TerminateEvent
- type URLAccessEvent
- type URLEvent
- type UserEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIEvent ¶
type APIEvent struct {
hook.Event
App App
Request interface{} // HTTP 请求对象
Path string
Method string
Headers map[string]string
Body interface{}
}
APIEvent API 请求事件
type APIResponseEvent ¶
type APIResponseEvent struct {
hook.Event
App App
Request interface{} // HTTP 请求对象
Response interface{} // HTTP 响应对象
Status int
Body interface{}
}
APIResponseEvent API 响应事件
type App ¶
type App interface {
// 基础应用方法
Bootstrap() error
IsBootstrapped() bool
Restart() error
DataDir() string
// 数据库访问
DB() *sql.DB
WithURLDB(fn func(interface{}) error) error
// 路由和HTTP服务(假设使用 Gin)
Router() RouterInterface
// 配置和日志
Config() ConfigInterface
Logger() LoggerInterface
// 应用生命周期钩子
OnBootstrap() *hook.Hook[*BootstrapEvent]
OnServe() *hook.Hook[*ServeEvent]
OnTerminate() *hook.Hook[*TerminateEvent]
// URL 相关钩子
OnURLAdd() *hook.Hook[*URLEvent]
OnURLAccess() *hook.Hook[*URLAccessEvent]
OnURLUpdate() *hook.Hook[*URLEvent]
OnURLDelete() *hook.Hook[*URLEvent]
// 用户相关钩子
OnUserLogin() *hook.Hook[*UserEvent]
OnUserLogout() *hook.Hook[*UserEvent]
OnUserRegister() *hook.Hook[*UserEvent]
// 分类和标签钩子
OnCategoryCreate() *hook.Hook[*CategoryEvent]
OnTagAdd() *hook.Hook[*TagEvent]
// API 钩子
OnAPIRequest() *hook.Hook[*APIEvent]
OnAPIResponse() *hook.Hook[*APIResponseEvent]
// 自定义事件钩子
OnCustomEvent() *hook.Hook[*CustomEvent]
// 待处理资源钩子
OnReadyResourceAdd() *hook.Hook[*ReadyResourceEvent]
}
App 定义 URLDB 应用的核心接口
type BaseApp ¶
type BaseApp struct {
// contains filtered or unexported fields
}
BaseApp 实现 App 接口的基础结构
func (*BaseApp) Config ¶
func (app *BaseApp) Config() ConfigInterface
func (*BaseApp) IsBootstrapped ¶
func (*BaseApp) Logger ¶
func (app *BaseApp) Logger() LoggerInterface
func (*BaseApp) OnAPIResponse ¶
func (app *BaseApp) OnAPIResponse() *hook.Hook[*APIResponseEvent]
func (*BaseApp) OnBootstrap ¶
func (app *BaseApp) OnBootstrap() *hook.Hook[*BootstrapEvent]
func (*BaseApp) OnCategoryCreate ¶
func (app *BaseApp) OnCategoryCreate() *hook.Hook[*CategoryEvent]
func (*BaseApp) OnCustomEvent ¶
func (app *BaseApp) OnCustomEvent() *hook.Hook[*CustomEvent]
func (*BaseApp) OnReadyResourceAdd ¶
func (app *BaseApp) OnReadyResourceAdd() *hook.Hook[*ReadyResourceEvent]
func (*BaseApp) OnTerminate ¶
func (app *BaseApp) OnTerminate() *hook.Hook[*TerminateEvent]
func (*BaseApp) OnURLAccess ¶
func (app *BaseApp) OnURLAccess() *hook.Hook[*URLAccessEvent]
func (*BaseApp) Router ¶
func (app *BaseApp) Router() RouterInterface
func (*BaseApp) SetConfig ¶
func (app *BaseApp) SetConfig(config ConfigInterface)
func (*BaseApp) SetDataDir ¶
func (*BaseApp) SetLogger ¶
func (app *BaseApp) SetLogger(logger LoggerInterface)
func (*BaseApp) SetRouter ¶
func (app *BaseApp) SetRouter(router RouterInterface)
func (*BaseApp) TriggerCustomEvent ¶
TriggerCustomEvent 触发自定义事件
func (*BaseApp) TriggerReadyResourceAdd ¶
func (app *BaseApp) TriggerReadyResourceAdd(readyResource *entity.ReadyResource, data map[string]interface{}) error
TriggerReadyResourceAdd 触发待处理资源添加事件
func (*BaseApp) TriggerURLAccess ¶
func (app *BaseApp) TriggerURLAccess(url *entity.Resource, accessLog interface{}, request, response interface{}) error
TriggerURLAccess 触发 URL 访问事件
func (*BaseApp) TriggerURLAdd ¶
TriggerURLAdd 触发 URL 添加事件
func (*BaseApp) TriggerUserLogin ¶
TriggerUserLogin 触发用户登录事件
type CategoryEvent ¶
CategoryEvent 分类相关事件
type ConfigInterface ¶
type ConfigInterface interface {
GetString(key string) string
GetInt(key string) int
GetBool(key string) bool
Get(key string) interface{}
Set(key string, value interface{})
}
ConfigInterface 配置接口
type CustomEvent ¶
CustomEvent 自定义事件
type LoggerInterface ¶
type LoggerInterface interface {
Debug(msg string, args ...interface{})
Info(msg string, args ...interface{})
Warn(msg string, args ...interface{})
Error(msg string, args ...interface{})
Fatal(msg string, args ...interface{})
}
LoggerInterface 日志接口
type ReadyResourceEvent ¶
type ReadyResourceEvent struct {
hook.Event
App App
ReadyResource *entity.ReadyResource
Data map[string]interface{} // 额外数据
}
ReadyResourceEvent 待处理资源事件
type RouterInterface ¶
type RouterInterface interface {
GET(path string, handler interface{})
POST(path string, handler interface{})
PUT(path string, handler interface{})
DELETE(path string, handler interface{})
PATCH(path string, handler interface{})
// 中间件支持
Use(middleware interface{})
Group(path string) RouterInterface
}
RouterInterface 路由接口(适配你的路由框架)
type ServeEvent ¶
type ServeEvent struct {
hook.Event
App App
Router RouterInterface
}
ServeEvent 服务启动事件
type URLAccessEvent ¶
type URLAccessEvent struct {
hook.Event
App App
URL *entity.Resource
AccessLog interface{} // 可以用 APIAccessLog
Request interface{} // HTTP 请求对象
Response interface{} // HTTP 响应对象
}
URLAccessEvent URL 访问事件
Click to show internal directories.
Click to hide internal directories.