Documentation
¶
Overview ¶
1. 通过重新实现 ixxx.go 接口 2. 在对应模块初始化之前注册实例 ipakku.Override.RegisterPakkuModuleImplement(val, interface-name, name) (如: init方法) 3. 再在启动时app.SetParam(key, name)就可以替代默认模块啦~
Index ¶
- Constants
- Variables
- type AppCache
- type AppConfig
- type AppEvent
- type AppService
- type AppSyncEvent
- type Application
- type ApplicationBootBuilder
- type Controller
- type ControllerConfig
- type CustomModuleBuilder
- type EventHandle
- type FilterConfigItem
- type FilterFunc
- type HTTPService
- type HTTPServiceConfig
- type HandlerFunc
- type ICache
- type IConfig
- type IEvent
- type Loader
- type Method
- type Module
- type ModuleEvent
- type ModuleEventBuilder
- type ModuleInfoRecorder
- type Modules
- type OnModuleEvent
- type Opts
- type PakkuApplication
- type PakkuConfigure
- type PakkuModuleBuilder
- type PakkuModulesGetter
- type ParamGetter
- type ParamSetter
- type Params
- type RPCService
- type RPCServiceConfig
- type Router
- type RouterConfig
- type Updater
- type Updaters
- type Utils
Constants ¶
const ( // CONFKEY_READTIMEOUTSECOND ReadTimeoutSecond CONFKEY_READTIMEOUTSECOND = "service.ReadTimeoutSecond" // CONFKEY_WRITETIMEOUTSECOND WriteTimeoutSecond CONFKEY_WRITETIMEOUTSECOND = "service.WriteTimeoutSecond" // CONFKEY_MAXHEADERBYTES MaxHeaderBytes CONFKEY_MAXHEADERBYTES = "service.MaxHeaderBytes" )
const ( // STAG_AUTOWIRED struct标签-自动注入标签 STAG_AUTOWIRED = "@autowired" // STAG_AUTOCONFIG struct标签-自动配置标签 STAG_AUTOCONFIG = "@autoConfig" // STAG_CONFIG_VALUE struct标签-自动配置-字段配置标签 STAG_CONFIG_VALUE = "@value" )
const ( // DEFT_VAL_APPNAME 默认实例名字 DEFT_VAL_APPNAME = "app" // PARAMS_KEY_APPNAME 实例名字KEY PARAMS_KEY_APPNAME = "app.name" // ERR_MSG_MODULE_NOT_FOUND 模块未找到 ERR_MSG_MODULE_NOT_FOUND = "the module was not found, model: %s" )
Variables ¶
var ErrCacheArgsEmpty = errors.New("cache value parameter cannot be empty")
ErrCacheArgsEmpty 必填字段为空
var ErrCacheArgsTypeError = errors.New("cache parameter type error")
ErrCacheArgsTypeError 缓存值参数类型错误
var ErrCacheLibIsExist = errors.New("cache lib is exist")
ErrCacheLibIsExist 缓存库重复注册
var ErrCacheLibNotExist = errors.New("cache lib not exist")
ErrCacheLibNotExist 缓存库没有注册
var ErrEventMethodUnsupported = errors.New("event method unsupported")
ErrEventMethodUnsupported 没有实现
var ErrNoCacheHit = errors.New("no cache hit")
ErrNoCacheHit 没有命中缓存
var ErrSyncEventRegistered = errors.New("sync event is registered")
ErrSyncEventRegistered 事件重复注册
var ErrSyncEventUnregistered = errors.New("sync event unregistered")
ErrSyncEventUnregistered 事件未注册
var ModuleID = moduleID{
AppConfig: "AppConfig",
AppCache: "AppCache",
AppEvent: "AppEvent",
AppService: "AppService",
}
ModuleID 模块ID
var PakkuConf = pakkuConfFuc{
SetPakkuModuleImplement: doSetPakkuModuleImplement,
GetPakkuModuleImplement: doGetPakkuModuleImplement,
RegisterPakkuModuleImplement: doRegisterPakkuModuleImplement,
AutowirePakkuModuleImplement: doAutowirePakkuModuleImplement,
SetModuleInfoRecorderImplement: doSetModuleInfoRecorderImplement,
GetModuleInfoRecorderImplement: doGetModuleInfoRecorderImplement,
}
PakkuConf PakkuConf配置, 如: 复写模块、设置模块信息记录器
Functions ¶
This section is empty.
Types ¶
type AppCache ¶
type AppCache interface { // RegLib lib: 库名(组名), second: 默认过期时间, -1为不过期 RegLib(clib string, second int64) error // Exists 返回key是否存在 Exists(clib string, key string) (bool, error) // Set 向lib库中设置键为key的值 // args[0] 为缓存值 args[2]如果存在, 则覆盖默认过期时间, 单位秒 Set(clib string, key string, args ...any) error // SetNX 向lib库中设置键为key的值, 当key不存在时设置成功, 并返回true // args[0] 为缓存值 args[2]如果存在, 则覆盖默认过期时间, 单位秒 SetNX(clib string, key string, args ...any) (bool, error) // Incrby 指定key以increment的值累加, 返回累加后的值 // args[0] 为缓存值 args[2]如果存在, 则覆盖默认过期时间, 单位秒 Incrby(clib string, key string, args ...any) (int64, error) // Get 读取缓存信息 Get(clib string, key string, val any) error // Del 删除缓存信息 Del(clib string, key string) error // Keys 获取库的所有key Keys(clib string) []string // Clear 清空库内容 Clear(clib string) }
AppCache 缓存模块
type AppConfig ¶
type AppConfig interface { // GetConfig 读取key的value信息, 返回 Object 对象, 里面的值可能是string或者map GetConfig(key string) utypes.Object // SetConfig 设置值 SetConfig(key string, value interface{}) error // ScanAndAutoConfig 扫描带有@autoconfig标签的字段, 并完成其配置 ScanAndAutoConfig(ptr interface{}) error // ScanAndAutoValue 扫描带有@autovalue标签的字段, 并完成其配置 ScanAndAutoValue(configPrefix string, ptr interface{}) error }
AppConfig app 配置模块
type AppEvent ¶
type AppEvent interface { PublishEvent(group string, name string, val interface{}) error ConsumerEvent(group string, name string, fun EventHandle) error }
AppEvent 事件模块, 默认未实现
type AppService ¶
type AppService interface { HTTPService RPCService StartHTTP(serviceCfg HTTPServiceConfig) StartRPC(serviceCfg RPCServiceConfig) }
AppService web服务即接口
type AppSyncEvent ¶
type AppSyncEvent interface { PublishSyncEvent(group string, name string, val interface{}) error ConsumerSyncEvent(group string, name string, fun EventHandle) error }
AppSyncEvent 本机同步事件模块[不开放自定义实现], 同步操作 只能注册一次
type Application ¶
type Application interface { // GetInstanceID 获取实例的ID GetInstanceID() string // Params 保存实例中的键值对数据 Params() Params // Modules 模块操作 Modules() Modules // Utils 工具 Utils() Utils }
Application 当前运行中的实例
type ApplicationBootBuilder ¶ added in v0.0.8
type ApplicationBootBuilder interface { // PakkuConfigure 应用配置操作 PakkuConfigure() PakkuConfigure // PakkuModules 默认模块启用操作 PakkuModules() PakkuModuleBuilder // CustomModules 自定义模块操作 CustomModules() CustomModuleBuilder // ModuleEvents 模块事件监听器 ModuleEvents() ModuleEventBuilder // Application 获取Application实例 Application() PakkuApplication // BootStart 加载&启动程序 BootStart() PakkuApplication }
ApplicationBootBuilder 应用初始化引导
type Controller ¶
type Controller interface {
AsController() ControllerConfig
}
Controller 注册对象为Controller
type ControllerConfig ¶
type ControllerConfig struct { RequestMapping string // 请求路径, 也可以是版本号(v1|v2...)作为路径的一部分; RouterConfig // 批量注册服务路径配置对象 FilterConfig []FilterConfigItem // 过滤器配置对象, 自动添加前缀路径(RequestMapping值) }
ControllerConfig 注册对象为Controller配置对象; RequestMapping 请求路径, 也可以是版本号(v1|v2...)作为路径的一部分; RouterConfig 批量注册服务路径配置对象
type CustomModuleBuilder ¶ added in v0.0.8
type CustomModuleBuilder interface { // AddModule 添加模块 AddModule(mt Module) CustomModuleBuilder // AddModules 添加模块 AddModules(mts ...Module) CustomModuleBuilder // ModuleEvents 模块事件监听器 ModuleEvents() ModuleEventBuilder // BootStart 加载&启动程序 BootStart() PakkuApplication }
CustomModuleBuilder 自定义模块操作
type FilterConfigItem ¶ added in v0.0.8
type FilterConfigItem struct { Path string // 指定的url, 自动添加RequestMapping前缀 Func FilterFunc // http请求过滤器, 返回bool, true: 继续, false: 停止 }
FilterConfigItem 过滤器配置对象
type FilterFunc ¶
type FilterFunc func(http.ResponseWriter, *http.Request) bool
FilterFunc http请求过滤器, 返回bool, true: 继续, false: 停止
var Filter4Passed FilterFunc = func(http.ResponseWriter, *http.Request) bool { return true }
Filter4Passed 空过滤器(通过的): 没有任何处理逻辑的过滤器
type HTTPService ¶
type HTTPService interface { // Get Get Get(url string, fun HandlerFunc) error // Post Post Post(url string, fun HandlerFunc) error // Put Put Put(url string, fun HandlerFunc) error // Patch Patch Patch(url string, fun HandlerFunc) error // Head Head Head(url string, fun HandlerFunc) error // Options Options Options(url string, fun HandlerFunc) error // Delete Delete Delete(url string, fun HandlerFunc) error // Any Any Any(url string, fun HandlerFunc) error // AsRouter 批量注册路由, 可以再指定一个前缀url AsRouter(url string, router Router) error // AsController 批量注册路由, 使用RequestMapping字段作为前缀url AsController(router Controller) error // Filter 注册请求过滤器 Filter(url string, fun FilterFunc) error // SetStaticDIR SetStaticDIR SetStaticDIR(path, dir string, fun FilterFunc) error // SetStaticFile SetStaticFile SetStaticFile(path, file string, fun FilterFunc) error }
HTTPService 服务
type HTTPServiceConfig ¶
type HTTPServiceConfig struct { Debug bool CertFile string KeyFile string ListenAddr string Server *http.Server }
HTTPServiceConfig 启动配置
type ICache ¶
type ICache interface { AppCache // Init 初始化缓存管理器, 一个对象只能初始化一次 Init(config AppConfig, appName string) }
ICache 缓存接口
type IConfig ¶
type IConfig interface { // Init 初始化解析器 Init(appName string) error // GetConfig 读取key的value信息, 返回 Object 对象, 里面的值可能是string或者map GetConfig(key string) (res utypes.Object) // SetConfig 设置值 SetConfig(key string, value interface{}) error }
IConfig 配置接口
type IEvent ¶
type IEvent interface { Init(conf AppConfig) error PublishEvent(name string, val string, obj interface{}) error ConsumerEvent(group string, name string, fun EventHandle) error }
IEvent 事件接口
type Loader ¶
type Loader interface { // GetInstanceID 获取实例的ID GetInstanceID() string // Load 装载&初始化模块, 初始化顺序: doReady -> doSetup -> doCheckVersion -> doInit -> doEnd Load(mt Module) // Loads 装载&初始化模块(自动分析模块依赖顺序), 初始化顺序: doReady -> doSetup -> doCheckVersion -> doInit -> doEnd Loads(mts ...Module) // SetModuleInfoRecorder 设置模块信息记录器 SetModuleInfoRecorder(moduleInfo ModuleInfoRecorder) // Application 获取当前实例 GetApplication() Application Params // Params 保存实例中的键值对数据 Modules // Modules 模块操作 }
Loader 模块加载器, 实例化后可实现统一管理模板
type ModuleEvent ¶
type ModuleEvent string
ModuleEvent 模块生命周期事件
var ModuleEventOnInit ModuleEvent = "OnInit"
var ModuleEventOnLoaded ModuleEvent = "OnLoaded"
var ModuleEventOnReady ModuleEvent = "OnReady"
var ModuleEventOnSetup ModuleEvent = "OnSetup"
var ModuleEventOnSetupSucced ModuleEvent = "OnSetupSucced"
var ModuleEventOnUpdate ModuleEvent = "OnUpdate"
var ModuleEventOnUpdateSucced ModuleEvent = "OnUpdateSucced"
type ModuleEventBuilder ¶ added in v0.0.8
type ModuleEventBuilder interface { // Listen 监听模块生命周期事件 Listen(name string, event ModuleEvent, val OnModuleEvent) ModuleEventBuilder // BootStart 加载&启动程序 BootStart() PakkuApplication }
ModuleEventBuilder 模块事件监听器
type ModuleInfoRecorder ¶ added in v0.0.8
type ModuleInfoRecorder interface { Init(appName string) error GetValue(key string) string SetValue(key string, value string) error }
ModuleInfoRecorder 用于记录模块信息
type Modules ¶ added in v0.0.8
type Modules interface { // GetModuleByName 根据模块Name获取模块指针记录, 可以获取一个已经实例化的模块 GetModuleByName(name string, val interface{}) error // GetModules 获取模块, 模块名字和接口名字一样才能正常获得 GetModules(val ...interface{}) error // GetModuleVersion 获取模块版本号 GetModuleVersion(name string) string // OnModuleEvent 监听模块生命周期事件 OnModuleEvent(name string, event ModuleEvent, val OnModuleEvent) }
Modules 模块操作
type OnModuleEvent ¶
type OnModuleEvent func(module interface{}, app Application)
OnModuleEvent 模块生命周期事件回调函数
type Opts ¶
type Opts struct { Name string // [可选] 模块ID, 不填则为结构体名称 Version float64 // [必填] 模块版本 Description string // [可选] 模块描述 Updaters func(app Application) Updaters // [可选] 模块升级执行器, 一个版本执行一次 OnReady func(app Application) // [可选] 每次加载模块开始之前执行 OnSetup func() // [可选] 模块安装, 一个模块只初始化一次 OnInit func() // [可选] 每次模块安装、升级后执行一次 }
Opts 模块配置项
type PakkuApplication ¶ added in v0.0.8
type PakkuApplication interface { Application // PakkuModules 默认模块Getter PakkuModules() PakkuModulesGetter }
PakkuApplication bootBuild实例化后的application
type PakkuConfigure ¶ added in v0.0.8
type PakkuConfigure interface { // SetLoggerOutput 设置日志输出方式 SetLoggerOutput(w io.Writer) PakkuConfigure // SetLoggerLevel 设置日志输出级别 NONE DEBUG INFO ERROR SetLoggerLevel(lv logs.LoggerLeve) PakkuConfigure // DisableBanner 禁止Banner输出 DisableBanner() PakkuConfigure // PakkuModules 启用默认携带的模块 PakkuModules() PakkuModuleBuilder // CustomModules 自定义模块操作 CustomModules() CustomModuleBuilder }
PakkuModule 应用配置
type PakkuModuleBuilder ¶ added in v0.0.8
type PakkuModuleBuilder interface { // EnableAppConfig 启用配置模块 EnableAppConfig() PakkuModuleBuilder // EnableAppCache 启用缓存模块 EnableAppCache() PakkuModuleBuilder // EnableAppEvent 启用事件模块 EnableAppEvent() PakkuModuleBuilder // EnableAppService 启用网络服务[WEB|RPC]模块 EnableAppService() PakkuModuleBuilder // CustomModules 自定义模块操作 CustomModules() CustomModuleBuilder // ModuleEvents 模块事件监听器 ModuleEvents() ModuleEventBuilder // BootStart 加载&启动程序 BootStart() PakkuApplication }
PakkuModule 默认模块启用操作
type PakkuModulesGetter ¶ added in v0.0.8
type PakkuModulesGetter interface { // GetAppConfig 获得配置模块 GetAppConfig() AppConfig // GetAppCache 获得缓存模块 GetAppCache() AppCache // GetAppEvent 获得事件模块 GetAppEvent() AppEvent // GetAppService 获得网络服务[WEB|RPC]模块 GetAppService() AppService }
PakkuModulesGetter 获取默认携带的模块
type ParamGetter ¶ added in v0.0.8
ParamGetter 只读 - 保存实例中的键值对数据
type ParamSetter ¶ added in v0.0.8
type ParamSetter interface { // SetParam 设置变量, 保存在当前实例内部 SetParam(key string, val interface{}) }
ParamSetter 只写 - 保存实例中的键值对数据
type RPCServiceConfig ¶
RPCServiceConfig 启动配置
type RouterConfig ¶
type RouterConfig serviceutil.RouterConfig
RouterConfig 批量注册服务路径配置对象; ToLowerCase bool 是否需要url转小写, 在未指定url(使用函数名字作为url的一部分)的情况下生效; HandlerFunc [][]interface{} 需要注册的函数 [{"Method(GET|POST...)", "HandlerFunc function"}, {"Method(GET|POST...)", "指定的url(可选参数)", "HandlerFunc function"}]
type Updater ¶ added in v0.0.4
type Updater interface { // Version 要升级到的版本号 Version() float64 // Execute 执行升级 Execute(app Application) error }
Updater 模块版本升级执行器