Documentation
¶
Index ¶
- Constants
- Variables
- func AtappAddModule[ModuleType AppModuleImpl](app AppImpl, module ModuleType) error
- func AtappGetModule[ModuleType AppModuleImpl](app AppImpl) ModuleType
- func ExpandExpression(input string) string
- func GetEnvUpperKey(key string) string
- func LoadConfigFromEnvironemnt(envPrefix string, configPb proto.Message, logger *log.Logger, ...) (bool, error)
- func LoadConfigFromOriginData(originData interface{}, prefixPath string, configPb proto.Message, ...) (err error)
- func LoadConfigFromOriginDataByPath(logger *log.Logger, originData interface{}, target proto.Message, ...) (err error)
- func LoadConfigFromYaml(configPath string, prefixPath string, configPb proto.Message, ...) (yamlData map[string]interface{}, err error)
- func LoadConfigOriginYaml(configPath string) (yamlData map[string]interface{}, err error)
- func LoadDefaultConfigMessageFields(configPb proto.Message, logger *log.Logger, dumpExistedSet *ConfigExistedIndex, ...) error
- func LoadLogCategoryConfigFromEnvironemnt(envPrefix string, logCategoryPb *atframe_protocol.AtappLogCategory, ...) bool
- func ParsePlainMessage(yamlData map[string]interface{}, msg proto.Message, logger *log.Logger) error
- func PrintBuildInfo()
- func RegisterBuildInfoCommand()
- func SetBuildInfo(version, gitCommit, gitBranch, buildTime, cfgVersion, buildMode string)
- type AppActionData
- type AppActionSender
- type AppConfig
- type AppFlag
- type AppImpl
- type AppInstance
- func (app *AppInstance) AddModule(typeInst lu.TypeID, module AppModuleImpl) error
- func (app *AppInstance) CheckFlag(flag AppFlag) bool
- func (app *AppInstance) GetAppContext() context.Context
- func (app *AppInstance) GetAppIdentity() string
- func (app *AppInstance) GetAppName() string
- func (app *AppInstance) GetAppVersion() string
- func (app *AppInstance) GetBuildVersion() string
- func (app *AppInstance) GetConfig() *AppConfig
- func (app *AppInstance) GetConfigFile() string
- func (app *AppInstance) GetDefaultLogger() *log.Logger
- func (app *AppInstance) GetHashCode() string
- func (app *AppInstance) GetId() uint64
- func (app *AppInstance) GetLogger(index int) *log.Logger
- func (app *AppInstance) GetModule(typeInst lu.TypeID) AppModuleImpl
- func (app *AppInstance) GetSysNow() time.Time
- func (app *AppInstance) GetTypeId() uint64
- func (app *AppInstance) GetTypeName() string
- func (app *AppInstance) Init(arguments []string) error
- func (app *AppInstance) InitLog(config *atframe_protocol.AtappLog) (*AppLog, error)
- func (app *AppInstance) IsClosed() bool
- func (app *AppInstance) IsClosing() bool
- func (app *AppInstance) IsInited() bool
- func (app *AppInstance) IsRunning() bool
- func (app *AppInstance) LoadConfig(configFile string, configurePrefixPath string, loadEnvironemntPrefix string, ...) (err error)
- func (app *AppInstance) LoadConfigByPath(target proto.Message, configurePrefixPath string, loadEnvironemntPrefix string, ...) error
- func (app *AppInstance) LoadLogConfigByPath(target *atframe_protocol.AtappLog, configurePrefixPath string, ...) error
- func (app *AppInstance) LoadOriginConfigData(configFile string) (err error)
- func (app *AppInstance) MakeAction(callback func(action *AppActionData) error, message_data []byte, ...) *AppActionSender
- func (app *AppInstance) PushAction(callback func(action *AppActionData) error, message_data []byte, ...) error
- func (app *AppInstance) Reload() error
- func (app *AppInstance) Run(arguments []string) error
- func (app *AppInstance) RunCommand(arguments []string) error
- func (app *AppInstance) RunOnce(tickTimer *time.Ticker) error
- func (app *AppInstance) SendMessage(targetId uint64, msgType int32, data []byte) error
- func (app *AppInstance) SendMessageByName(targetName string, msgType int32, data []byte) error
- func (app *AppInstance) SetEventHandler(eventType string, handler EventHandler)
- func (app *AppInstance) SetFlag(flag AppFlag, value bool) bool
- func (app *AppInstance) Stop() error
- func (app *AppInstance) TriggerEvent(eventType string, args *AppActionSender) int
- type AppLog
- type AppMode
- type AppModuleBase
- func (m *AppModuleBase) Active()
- func (m *AppModuleBase) Cleanup()
- func (m *AppModuleBase) Disable()
- func (m *AppModuleBase) Enable()
- func (m *AppModuleBase) GetApp() AppImpl
- func (m *AppModuleBase) GetSysNow() time.Time
- func (m *AppModuleBase) IsActived() bool
- func (m *AppModuleBase) IsEnabled() bool
- func (m *AppModuleBase) OnBind()
- func (m *AppModuleBase) OnUnbind()
- func (m *AppModuleBase) Ready()
- func (m *AppModuleBase) Reload() error
- func (m *AppModuleBase) Setup(_initCtx context.Context) error
- func (m *AppModuleBase) SetupLog(_initCtx context.Context) error
- func (m *AppModuleBase) Stop() (bool, error)
- func (m *AppModuleBase) Tick(_initCtx context.Context) bool
- func (m *AppModuleBase) Timeout()
- func (m *AppModuleBase) Unactive()
- type AppModuleImpl
- type BuildInfo
- type CommandHandler
- type CommandManager
- type ConfigExistedIndex
- type EventHandler
- type LoadConfigOptions
- type Message
Constants ¶
View Source
const ( SPLITCHAR = 1 << iota STRINGSYM TRANSLATE CMDSPLIT )
定义字符映射常量
Variables ¶
View Source
var ( Version = "v0.0.0" Commit = "unknown" Branch = "unknown" BuildTime = "unknown" ConfigVer = "unknown" BuildMode = "DEBUG" )
编译时注入的顶级变量(用于 ldflags)
Functions ¶
func AtappAddModule ¶
func AtappAddModule[ModuleType AppModuleImpl](app AppImpl, module ModuleType) error
func AtappGetModule ¶
func AtappGetModule[ModuleType AppModuleImpl](app AppImpl) ModuleType
func ExpandExpression ¶
ExpandExpression expands environment variable expressions in the input string. Supports $VAR, ${VAR}, ${VAR:-default}, ${VAR:+word}, \$ escape, and nested expressions.
func GetEnvUpperKey ¶
func LoadConfigFromEnvironemnt ¶
func LoadConfigFromEnvironemnt(envPrefix string, configPb proto.Message, logger *log.Logger, loadOptions *LoadConfigOptions, dumpExistedSet *ConfigExistedIndex, existedSetPrefix string, ) (bool, error)
func LoadConfigFromOriginData ¶
func LoadConfigFromOriginData(originData interface{}, prefixPath string, configPb proto.Message, logger *log.Logger,
loadOptions *LoadConfigOptions, dumpExistedSet *ConfigExistedIndex, existedSetPrefix string,
) (err error)
func LoadConfigFromOriginDataByPath ¶
func LoadConfigFromOriginDataByPath(logger *log.Logger, originData interface{}, target proto.Message, configurePrefixPath string, loadEnvironemntPrefix string, loadOptions *LoadConfigOptions, existedKeys *ConfigExistedIndex, existedSetPrefix string, ) (err error)
配置管理
func LoadConfigFromYaml ¶
func LoadConfigOriginYaml ¶
func LoadLogCategoryConfigFromEnvironemnt ¶
func LoadLogCategoryConfigFromEnvironemnt(envPrefix string, logCategoryPb *atframe_protocol.AtappLogCategory, logger *log.Logger, dumpExistedSet *ConfigExistedIndex, existedSetPrefix string, ) bool
LoadLogCategoryConfigFromEnvironemnt 从环境变量加载日志配置 支持特殊的 sink 配置格式: <前缀>_<CATEGORY_NAME>_<sink 下标>_<大写字段名>
func ParsePlainMessage ¶
func RegisterBuildInfoCommand ¶
func RegisterBuildInfoCommand()
RegisterInfoCommand 处理 --info 标志 这个函数会在应用启动前被调用,处理 --info 标志 仅检查命令行参数中是否有 --info,不使用全局 flag 包避免污染其他参数
func SetBuildInfo ¶
func SetBuildInfo(version, gitCommit, gitBranch, buildTime, cfgVersion, buildMode string)
SetBuildInfo 设置编译信息(由 build 命令注入)
Types ¶
type AppActionData ¶
AppAction对象
type AppActionSender ¶
type AppActionSender struct {
// contains filtered or unexported fields
}
type AppConfig ¶
type AppConfig struct {
// Runtime配置
HashCode string
AppName string
BuildVersion string
AppVersion string
ConfigFile string
PidFile string
ExecutePath string
// 日志配置
StartupLog []string
StartupErrorFile string
CrashOutputFile string
// 文件配置
ConfigPb *atframe_protocol.AtappConfigure
ConfigLog *atframe_protocol.AtappLog
ConfigOriginData interface{}
}
App 配置
type AppImpl ¶
type AppImpl interface {
Run(arguments []string) error
Init(arguments []string) error
RunOnce(tickTimer *time.Ticker) error
Stop() error
Reload() error
GetId() uint64
GetTypeId() uint64
GetTypeName() string
GetAppName() string
GetAppIdentity() string
GetHashCode() string
GetAppVersion() string
GetBuildVersion() string
GetConfigFile() string
GetSysNow() time.Time
AddModule(typeInst lu.TypeID, module AppModuleImpl) error
GetModule(typeInst lu.TypeID) AppModuleImpl
// 消息相关
SendMessage(targetId uint64, msgType int32, data []byte) error
SendMessageByName(targetName string, msgType int32, data []byte) error
// 事件相关
SetEventHandler(eventType string, handler EventHandler)
TriggerEvent(eventType string, args *AppActionSender) int
// 自定义Action
PushAction(callback func(action *AppActionData) error, message_data []byte, private_data interface{}) error
// 配置相关
GetConfig() *AppConfig
LoadConfig(configFile string, configurePrefixPath string, loadEnvironemntPrefix string, existedKeys *ConfigExistedIndex) error
LoadConfigByPath(target proto.Message,
configurePrefixPath string, loadEnvironemntPrefix string,
existedKeys *ConfigExistedIndex, existedSetPrefix string,
) error
LoadLogConfigByPath(target *atframe_protocol.AtappLog,
configurePrefixPath string, loadEnvironemntPrefix string,
existedKeys *ConfigExistedIndex, existedSetPrefix string,
) error
// 状态相关
IsInited() bool
IsRunning() bool
IsClosing() bool
IsClosed() bool
CheckFlag(flag AppFlag) bool
SetFlag(flag AppFlag, value bool) bool
// 生命周期管理
GetAppContext() context.Context
// Logger
GetDefaultLogger() *log.Logger
GetLogger(index int) *log.Logger
}
App 应用接口
func CreateAppInstance ¶
func CreateAppInstance() AppImpl
type AppInstance ¶
type AppInstance struct {
// contains filtered or unexported fields
}
func (*AppInstance) AddModule ¶
func (app *AppInstance) AddModule(typeInst lu.TypeID, module AppModuleImpl) error
func (*AppInstance) CheckFlag ¶
func (app *AppInstance) CheckFlag(flag AppFlag) bool
func (*AppInstance) GetAppContext ¶
func (app *AppInstance) GetAppContext() context.Context
func (*AppInstance) GetAppIdentity ¶
func (app *AppInstance) GetAppIdentity() string
func (*AppInstance) GetAppName ¶
func (app *AppInstance) GetAppName() string
func (*AppInstance) GetAppVersion ¶
func (app *AppInstance) GetAppVersion() string
func (*AppInstance) GetBuildVersion ¶
func (app *AppInstance) GetBuildVersion() string
func (*AppInstance) GetConfig ¶
func (app *AppInstance) GetConfig() *AppConfig
func (*AppInstance) GetConfigFile ¶
func (app *AppInstance) GetConfigFile() string
func (*AppInstance) GetDefaultLogger ¶
func (app *AppInstance) GetDefaultLogger() *log.Logger
func (*AppInstance) GetHashCode ¶
func (app *AppInstance) GetHashCode() string
func (*AppInstance) GetModule ¶
func (app *AppInstance) GetModule(typeInst lu.TypeID) AppModuleImpl
func (*AppInstance) GetSysNow ¶
func (app *AppInstance) GetSysNow() time.Time
func (*AppInstance) GetTypeId ¶
func (app *AppInstance) GetTypeId() uint64
func (*AppInstance) GetTypeName ¶
func (app *AppInstance) GetTypeName() string
func (*AppInstance) Init ¶
func (app *AppInstance) Init(arguments []string) error
func (*AppInstance) InitLog ¶
func (app *AppInstance) InitLog(config *atframe_protocol.AtappLog) (*AppLog, error)
func (*AppInstance) IsClosed ¶
func (app *AppInstance) IsClosed() bool
func (*AppInstance) IsClosing ¶
func (app *AppInstance) IsClosing() bool
func (*AppInstance) IsInited ¶
func (app *AppInstance) IsInited() bool
func (*AppInstance) IsRunning ¶
func (app *AppInstance) IsRunning() bool
func (*AppInstance) LoadConfig ¶
func (app *AppInstance) LoadConfig(configFile string, configurePrefixPath string, loadEnvironemntPrefix string, existedKeys *ConfigExistedIndex, ) (err error)
配置管理
func (*AppInstance) LoadConfigByPath ¶
func (app *AppInstance) LoadConfigByPath(target proto.Message, configurePrefixPath string, loadEnvironemntPrefix string, existedKeys *ConfigExistedIndex, existedSetPrefix string, ) error
func (*AppInstance) LoadLogConfigByPath ¶
func (app *AppInstance) LoadLogConfigByPath(target *atframe_protocol.AtappLog, configurePrefixPath string, loadEnvironemntPrefix string, existedKeys *ConfigExistedIndex, existedSetPrefix string, ) error
func (*AppInstance) LoadOriginConfigData ¶
func (app *AppInstance) LoadOriginConfigData(configFile string) (err error)
func (*AppInstance) MakeAction ¶
func (app *AppInstance) MakeAction(callback func(action *AppActionData) error, message_data []byte, private_data interface{}) *AppActionSender
func (*AppInstance) PushAction ¶
func (app *AppInstance) PushAction(callback func(action *AppActionData) error, message_data []byte, private_data interface{}) error
辅助方法:写入PID文件
func (*AppInstance) Reload ¶
func (app *AppInstance) Reload() error
func (*AppInstance) Run ¶
func (app *AppInstance) Run(arguments []string) error
func (*AppInstance) RunCommand ¶
func (app *AppInstance) RunCommand(arguments []string) error
func (*AppInstance) SendMessage ¶
func (app *AppInstance) SendMessage(targetId uint64, msgType int32, data []byte) error
消息相关
func (*AppInstance) SendMessageByName ¶
func (app *AppInstance) SendMessageByName(targetName string, msgType int32, data []byte) error
func (*AppInstance) SetEventHandler ¶
func (app *AppInstance) SetEventHandler(eventType string, handler EventHandler)
事件相关
func (*AppInstance) Stop ¶
func (app *AppInstance) Stop() error
func (*AppInstance) TriggerEvent ¶
func (app *AppInstance) TriggerEvent(eventType string, args *AppActionSender) int
type AppModuleBase ¶
type AppModuleBase struct {
// contains filtered or unexported fields
}
func CreateAppModuleBase ¶
func CreateAppModuleBase(owner AppImpl) AppModuleBase
func (*AppModuleBase) Active ¶
func (m *AppModuleBase) Active()
func (*AppModuleBase) Cleanup ¶
func (m *AppModuleBase) Cleanup()
func (*AppModuleBase) Disable ¶
func (m *AppModuleBase) Disable()
func (*AppModuleBase) Enable ¶
func (m *AppModuleBase) Enable()
func (*AppModuleBase) GetApp ¶
func (m *AppModuleBase) GetApp() AppImpl
func (*AppModuleBase) GetSysNow ¶
func (m *AppModuleBase) GetSysNow() time.Time
func (*AppModuleBase) IsActived ¶
func (m *AppModuleBase) IsActived() bool
func (*AppModuleBase) IsEnabled ¶
func (m *AppModuleBase) IsEnabled() bool
func (*AppModuleBase) OnBind ¶
func (m *AppModuleBase) OnBind()
func (*AppModuleBase) OnUnbind ¶
func (m *AppModuleBase) OnUnbind()
func (*AppModuleBase) Ready ¶
func (m *AppModuleBase) Ready()
func (*AppModuleBase) Reload ¶
func (m *AppModuleBase) Reload() error
func (*AppModuleBase) Stop ¶
func (m *AppModuleBase) Stop() (bool, error)
func (*AppModuleBase) Timeout ¶
func (m *AppModuleBase) Timeout()
func (*AppModuleBase) Unactive ¶
func (m *AppModuleBase) Unactive()
type AppModuleImpl ¶
type AppModuleImpl interface {
GetApp() AppImpl
Name() string
// Call this callback when a module is added into atapp for the first time
OnBind()
// Call this callback when a module is removed from atapp
OnUnbind()
// This callback is called after load configure and before initialization(include log)
Setup(parent context.Context) error
// This function will be called after reload and before init
SetupLog(parent context.Context) error
// This callback is called to initialize a module
Init(parent context.Context) error
// This callback is called after all modules are initialized successfully and the atapp is ready to run
Ready()
// This callback is called after configure is reloaded
Reload() error
// This callback may be called more than once, when the first return false, or this module will be disabled.
Stop() (bool, error)
// This callback only will be call once after all module stopped
Cleanup()
// This callback be called if the module can not be stopped even in a long time.
// After this event, all module and atapp will be forced stopped.
Timeout()
// This function will be called in every tick if it's actived. return true when busy.
Tick(parent context.Context) bool
IsActived() bool
Active()
Unactive()
IsEnabled() bool
Enable()
Disable()
}
App 应用接口
type BuildInfo ¶
type BuildInfo struct {
Version string // 版本号
GitCommit string // Git 提交哈希
GitBranch string // Git 分支
BuildTime string // 构建时间
ConfigVersion string // 构建配置
BuildMode string // DEBUG 或 Release
}
BuildInfo 存储编译注入的信息
type CommandManager ¶
type CommandManager struct {
// contains filtered or unexported fields
}
func NewCommandManager ¶
func NewCommandManager() *CommandManager
func (*CommandManager) ExecuteCommand ¶
func (cm *CommandManager) ExecuteCommand(app *AppInstance, command string, args []string) error
func (*CommandManager) ListCommands ¶
func (cm *CommandManager) ListCommands() []string
func (*CommandManager) RegisterCommand ¶
func (cm *CommandManager) RegisterCommand(name string, handler CommandHandler)
type ConfigExistedIndex ¶
func CreateConfigExistedIndex ¶
func CreateConfigExistedIndex() *ConfigExistedIndex
func (*ConfigExistedIndex) MutableExistedSet ¶
func (i *ConfigExistedIndex) MutableExistedSet() map[string]struct{}
func (*ConfigExistedIndex) MutableMapKeyIndex ¶
func (i *ConfigExistedIndex) MutableMapKeyIndex() map[string]int
type LoadConfigOptions ¶
type LoadConfigOptions struct {
ReorderListIndexByField string
}
Click to show internal directories.
Click to hide internal directories.