Documentation ¶
Overview ¶
1. 通过重新实现 ixxx.go 接口 2. 在对应模块初始化之前注册实例 ipakku.Override.RegisterInterfaceImpl(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 ApplicationBoot
- type Controller
- type ControllerConfig
- type EventHandle
- type FilterConfig
- type FilterFunc
- type HTTPService
- type HTTPServiceConfig
- type HandlerFunc
- type ICache
- type IConfig
- type IEvent
- type Loader
- type Method
- type Module
- type ModuleEvent
- type ModuleInfo
- type OnModuleEvent
- type Opts
- type RPCService
- type RPCServiceConfig
- type Router
- type RouterConfig
- type Updater
- type Updaters
Constants ¶
const ( // CONFKEY_READTIMEOUTSECOND ReadTimeoutSecond CONFKEY_READTIMEOUTSECOND = "service.ReadTimeoutSecond" // CONFKEY_WRITETIMEOUTSECOND WriteTimeoutSecond CONFKEY_WRITETIMEOUTSECOND = "service.WriteTimeoutSecond" // CONFKEY_MAXHEADERBYTES MaxHeaderBytes CONFKEY_MAXHEADERBYTES = "service.MaxHeaderBytes" )
const ( // PAKKUTAG_AUTOWIRED 自动注入标签 PAKKUTAG_AUTOWIRED = "@autowired" // PAKKUTAG_AUTOCONFIG 自动配置标签 PAKKUTAG_AUTOCONFIG = "@autoConfig" // PAKKUTAG_CONFIG_VALUE 自动配置-字段配置标签 PAKKUTAG_CONFIG_VALUE = "@value" )
const ( // CONST_APPNAME 示例名字 CONST_APPNAME = "app" // PARAMKEY_APPNAME 实例名字KEY PARAMKEY_APPNAME = "app.name" // ErrModuleNotFoundStr 模块未找到 ErrModuleNotFoundStr = "the module was not found, model: %s" )
Variables ¶
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 Override = overrideFuc{
SetInterfaceDefaultImpl: doSetInterfaceDefaultImpl,
RegisterInterfaceImpl: doRegisterInterfaceImpl,
AutowireInterfaceImpl: doAutowireInterfaceImpl,
GetImplementByName: doGetImplementByName,
SetModuleInfoImpl: doSetModuleInfoImpl,
GetModuleInfoImpl: doGetModuleInfoImpl,
}
Override 复写模块静态方法
Functions ¶
This section is empty.
Types ¶
type AppCache ¶
type AppCache interface { // lib为库名, second:过期时间-1为不过期 RegLib(clib string, second int64) error // Set 向lib库中设置键为key的值tb Set(clib string, key string, tb interface{}) error // Get 读取缓存信息 Get(clib string, key string, val interface{}) error // Del 删除缓存信息 Del(clib string, key string) error // Keys 获取库的所有key Keys(clib string) []string // Clear 清空库内容 Clear(clib string) }
AppCache app 缓存模块
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 // LoadModule 装载&初始化模块 - DO Setup -> Check Ver -> Do Init LoadModule(mt Module) Application // LoadModules 装载&初始化模块 - DO Setup -> Check Ver -> Do Init LoadModules(mts ...Module) Application // GetParam 获取变量, 模板加载器实例上的变量 GetParam(key string) utypes.Object // SetParam 设置变量, 保存在模板加载器实例内部 SetParam(key string, val interface{}) // OnModuleEvent 监听模块生命周期事件 OnModuleEvent(name string, event ModuleEvent, val OnModuleEvent) // GetModuleByName 根据模块Name获取模块指针记录, 可以获取一个已经实例化的模块 GetModuleByName(name string, val interface{}) error // GetModule 批量获取模块, 模块名字和接口名字一样才能正常获得 GetModules(val ...interface{}) error // Invoke 模块调用, 返回 []reflect.Value, 返回值暂时无法处理 Invoke(name string, method string, params ...interface{}) ([]reflect.Value, error) // AutoWired 自动注入依赖对象 AutoWired(structobj interface{}) error }
Application 应用实例, 继承 loader.Loader
type ApplicationBoot ¶
type ApplicationBoot interface { // BootStart 加载&启动程序 BootStart() Application // GetApplication 获取Application GetApplication() Application // AddModule 添加模块 AddModule(mt Module) ApplicationBoot // AddModules 添加模块 AddModules(mts ...Module) ApplicationBoot // EnableCoreModule 启用默认的核心模块 EnableCoreModule() ApplicationBoot // EnableNetModule 启用默认的网络服务模块 EnableNetModule() ApplicationBoot // SetLoggerOutput 设置日志输出方式 SetLoggerOutput(w io.Writer) ApplicationBoot // SetLoggerLevel 设置日志输出级别 NONE DEBUG INFO ERROR SetLoggerLevel(lv logs.LoggerLeve) ApplicationBoot // DisableBanner 禁止Banner输出 DisableBanner() ApplicationBoot }
ApplicationBoot 应用初始化引导
type Controller ¶
type Controller interface {
AsController() ControllerConfig
}
Controller 注册对象为Controller
type ControllerConfig ¶
type ControllerConfig struct { RequestMapping string // 请求路径, 也可以是版本号(v1|v2...)作为路径的一部分; RouterConfig // 批量注册服务路径配置对象 FilterConfig // 过滤器配置对象, 自动添加前缀路径(RequestMapping值) }
ControllerConfig 注册对象为Controller配置对象; RequestMapping 请求路径, 也可以是版本号(v1|v2...)作为路径的一部分; RouterConfig 批量注册服务路径配置对象
type FilterConfig ¶
type FilterConfig struct {
FilterFunc [][]interface{} // 需要注册的函数(注意注册顺序) [{"指定的url", "FilterFunc function"}]
}
FilterConfig 过滤器配置对象
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 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 { CertFile string KeyFile string ListenAddr string Server *http.Server }
HTTPServiceConfig 启动配置
type ICache ¶
type ICache interface { // Init 初始化缓存管理器, 一个对象只能初始化一次 Init(config AppConfig, appName string) // lib为库名, second:过期时间-1为不过期 RegLib(clib string, second int64) error // Set 向lib库中设置键为key的值tb Set(clib string, key string, tb interface{}) error // Get 读取缓存信息 Get(clib string, key string, val interface{}) error // Del 删除缓存信息 Del(clib string, key string) error // Keys 获取库的所有key Keys(clib string) []string // Clear 清空库内容 Clear(clib 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) // GetParam 获取变量, 模板加载器实例上的变量 GetParam(key string) utypes.Object // SetParam 设置变量, 保存在模板加载器实例内部 SetParam(key string, val interface{}) // GetModuleVersion 获取模块版本号 GetModuleVersion(name string) string // OnModuleEvent 监听模块生命周期事件 OnModuleEvent(name string, event ModuleEvent, val OnModuleEvent) // SetModuleInfoHandler 设置模块信息记录器 SetModuleInfoHandler(moduleInfo ModuleInfo) // GetModuleByName 根据模块Name获取模块指针记录, 可以获取一个已经实例化的模块 GetModuleByName(name string, val interface{}) error // GetModules 获取模块, 模块名字和接口名字一样才能正常获得 GetModules(val ...interface{}) error // Invoke 模块调用, 返回 []reflect.Value, 返回值暂时无法处理 Invoke(name string, method string, params ...interface{}) ([]reflect.Value, error) // AutoWired 自动注入依赖对象 AutoWired(structobj interface{}) error }
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 ModuleInfo ¶
type ModuleInfo interface { Init(appName string) error GetValue(key string) string SetValue(key string, value string) error }
ModuleInfo 用于记录模块信息
type OnModuleEvent ¶
type OnModuleEvent func(module interface{}, loader Loader)
OnModuleEvent 模块生命周期事件回调函数
type Opts ¶
type Opts struct { Name string // [可选] 模块ID, 不填则为结构体名称 Version float64 // [必填] 模块版本 Description string // [可选] 模块描述 Updaters func(mctx Loader) Updaters // [可选] 模块升级执行器, 一个版本执行一次 OnReady func(mctx Loader) // [可选] 每次加载模块开始之前执行 OnSetup func() // [可选] 模块安装, 一个模块只初始化一次 OnInit func() // [可选] 每次模块安装、升级后执行一次 }
Opts 模块配置项
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(mctx Loader) error }
Updater 模块版本升级执行器