core

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

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 NewBaseApp

func NewBaseApp() *BaseApp

NewBaseApp 创建新的基础应用实例

func (*BaseApp) Bootstrap

func (app *BaseApp) Bootstrap() error

func (*BaseApp) Config

func (app *BaseApp) Config() ConfigInterface

func (*BaseApp) DB

func (app *BaseApp) DB() *sql.DB

func (*BaseApp) DataDir

func (app *BaseApp) DataDir() string

func (*BaseApp) IsBootstrapped

func (app *BaseApp) IsBootstrapped() bool

func (*BaseApp) Logger

func (app *BaseApp) Logger() LoggerInterface

func (*BaseApp) OnAPIRequest

func (app *BaseApp) OnAPIRequest() *hook.Hook[*APIEvent]

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) OnServe

func (app *BaseApp) OnServe() *hook.Hook[*ServeEvent]

func (*BaseApp) OnTagAdd

func (app *BaseApp) OnTagAdd() *hook.Hook[*TagEvent]

func (*BaseApp) OnTerminate

func (app *BaseApp) OnTerminate() *hook.Hook[*TerminateEvent]

func (*BaseApp) OnURLAccess

func (app *BaseApp) OnURLAccess() *hook.Hook[*URLAccessEvent]

func (*BaseApp) OnURLAdd

func (app *BaseApp) OnURLAdd() *hook.Hook[*URLEvent]

func (*BaseApp) OnURLDelete

func (app *BaseApp) OnURLDelete() *hook.Hook[*URLEvent]

func (*BaseApp) OnURLUpdate

func (app *BaseApp) OnURLUpdate() *hook.Hook[*URLEvent]

func (*BaseApp) OnUserLogin

func (app *BaseApp) OnUserLogin() *hook.Hook[*UserEvent]

func (*BaseApp) OnUserLogout

func (app *BaseApp) OnUserLogout() *hook.Hook[*UserEvent]

func (*BaseApp) OnUserRegister

func (app *BaseApp) OnUserRegister() *hook.Hook[*UserEvent]

func (*BaseApp) Restart

func (app *BaseApp) Restart() error

func (*BaseApp) Router

func (app *BaseApp) Router() RouterInterface

func (*BaseApp) SetConfig

func (app *BaseApp) SetConfig(config ConfigInterface)

func (*BaseApp) SetDB

func (app *BaseApp) SetDB(db *sql.DB)

func (*BaseApp) SetDataDir

func (app *BaseApp) SetDataDir(dir string)

func (*BaseApp) SetLogger

func (app *BaseApp) SetLogger(logger LoggerInterface)

func (*BaseApp) SetRouter

func (app *BaseApp) SetRouter(router RouterInterface)

func (*BaseApp) TriggerCustomEvent

func (app *BaseApp) TriggerCustomEvent(name string, data map[string]interface{}) error

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

func (app *BaseApp) TriggerURLAdd(url *entity.Resource, data map[string]interface{}) error

TriggerURLAdd 触发 URL 添加事件

func (*BaseApp) TriggerUserLogin

func (app *BaseApp) TriggerUserLogin(user *entity.User, data map[string]interface{}) error

TriggerUserLogin 触发用户登录事件

func (*BaseApp) WithURLDB

func (app *BaseApp) WithURLDB(fn func(interface{}) error) error

type BootstrapEvent

type BootstrapEvent struct {
	hook.Event
	App App
}

BootstrapEvent 应用启动事件

type CategoryEvent

type CategoryEvent struct {
	hook.Event
	App      App
	Category *entity.Category
}

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

type CustomEvent struct {
	hook.Event
	App  App
	Name string
	Data map[string]interface{}
}

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 TagEvent

type TagEvent struct {
	hook.Event
	App App
	Tag *entity.Tag
	URL *entity.Resource
}

TagEvent 标签相关事件

type TerminateEvent

type TerminateEvent struct {
	hook.Event
	App App
}

TerminateEvent 应用终止事件

type URLAccessEvent

type URLAccessEvent struct {
	hook.Event
	App       App
	URL       *entity.Resource
	AccessLog interface{} // 可以用 APIAccessLog
	Request   interface{} // HTTP 请求对象
	Response  interface{} // HTTP 响应对象
}

URLAccessEvent URL 访问事件

type URLEvent

type URLEvent struct {
	hook.Event
	App  App
	URL  *entity.Resource
	Data map[string]interface{} // 额外数据
}

URLEvent URL 相关事件

type UserEvent

type UserEvent struct {
	hook.Event
	App  App
	User *entity.User
	Data map[string]interface{} // 额外数据,如登录信息等
}

UserEvent 用户相关事件

Jump to

Keyboard shortcuts

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