Documentation
¶
Index ¶
- Constants
- Variables
- func FlagDefines()
- func GetSecretWithAppRole(keypath string, vaultAdd string) (map[string]interface{}, error)
- func MarshalConfig(lconf *LiveConfig) (conf []byte, err error)
- func SetDefaultLine(line Line)
- func SetLogger(log SLogger)
- func UnMarshalConfig(conf []byte, obj interface{}) (err error)
- type AfterAllDestroyer
- type AfterAllInjecter
- type AfterAllStarter
- type AllEvent
- type BeforeAllStopper
- type BuildNewer
- type Builder
- type Checker
- type Cmd
- type CmdParameterName
- type Config
- type ConfigTypeLive
- type Creator
- type Destroyer
- type Dot
- type Error
- type Errorer
- type Event
- type Eventer
- type Events
- type GetInterfaceType
- type HotConfig
- type Injected
- type Injecter
- type Level
- type Lifer
- type Line
- type Live
- type LiveConfig
- type LiveEvents
- type LiveID
- type LogConfig
- type MakeStringer
- type MetaLivesConfig
- type Metadata
- type Newer
- type SConfig
- type SLogger
- type SetterLine
- type SetterTypeAndLiveID
- type Starter
- type StatusType
- type Statuser
- type Stopper
- type StringFromEnv
- type Tager
- type TypeEvents
- type TypeID
- type TypeLives
Constants ¶
const ( //TagDot tag dot TagDot = "dot" //CanNull allow nil, if do not find the dot , set it nil CanNull = "?" )
const ( //LogLiveID log dot live id LogLiveID = "d8299d21-4f43-48bd-9a5c-654c4395ea17" // DebugLevel logs are typically voluminous, and are usually disabled in // production. DebugLevel = zapcore.DebugLevel // InfoLevel is the default logging priority. InfoLevel = zapcore.InfoLevel // WarnLevel logs are more important than Info, but don't need individual // human review. WarnLevel = zapcore.WarnLevel // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. ErrorLevel = zapcore.ErrorLevel //FatalLevel DPanicLevel logs are particularly important errors. In development the // logger panics after writing the message. FatalLevel = zapcore.FatalLevel )
const (
//SconfigTypeID scofig dot type id
SconfigTypeID = "484ef01d-3c04-4517-a643-2d776a9ae758"
)
Variables ¶
var SError = &Error{}
SError error object frequently used by dot
Functions ¶
func GetSecretWithAppRole ¶ added in v0.2.8
Fetches a key-value secret (kv-v2) after authenticating via AppRole.
func MarshalConfig ¶
func MarshalConfig(lconf *LiveConfig) (conf []byte, err error)
MarshalConfig marshal config
func SetLogger ¶
func SetLogger(log SLogger)
SetLogger Set default log, This method does not consider thread security, Adjusting value is not suggested after program initialization
func UnMarshalConfig ¶
UnMarshalConfig unmarshal config
Types ¶
type AfterAllDestroyer ¶ added in v0.2.0
type AfterAllDestroyer interface {
AfterAllDestroy(l Line)
}
AfterAllDestroyer After all destroy, before builder AfterDestroy
type AfterAllInjecter ¶
type AfterAllInjecter interface {
AfterAllInject(l Line)
}
AfterAllInjecter After all inject, before builder AfterStart
type AfterAllStarter ¶
type AfterAllStarter interface {
AfterAllStart(l Line)
}
AfterAllStarter After all start, before builder AfterStart
type BeforeAllStopper ¶
type BeforeAllStopper interface {
BeforeAllStop(l Line)
}
BeforeAllStopper Call before all stop, after Builder BeforeStop
type BuildNewer ¶
BuildNewer Add typeid, newer for dot in config file This function is run after line create, also you can add other initialized content
type Builder ¶
type Builder struct {
Add BuildNewer
BeforeCreate AllEvent //Before all dot create
AfterCreate AllEvent //after all dot create
BeforeStart AllEvent //Before all dot start
AfterStart AllEvent //After all dot start
BeforeStop AllEvent //Before all dot stop
AfterStop AllEvent //After all dot stop
BeforeDestroy AllEvent //Before all dot destroy
AfterDestroy AllEvent //After all dot destroy
LineLiveID string //line unique id, default value is “default”
}
Builder builder line dot
type Checker ¶
type Checker interface {
Check(args interface{}) interface{}
}
Checker Check dot,run some verification or test data, return the result
type Cmd ¶
type Cmd struct {
//ConfigPath config file path
ConfigPath string
//ConfigFile config file name without path
ConfigFile string
}
Cmd type general command line parameters
var GCmd Cmd
GCmd Global variables general command line parameters
type CmdParameterName ¶
type CmdParameterName string
CmdParameterName Command line parameter name
const ( //Config file path, add Cmd to show relations with struct cmd CmdConfigPath CmdParameterName = "configpath" //Config file name without path CmdConfigFile CmdParameterName = "configfile" )
Command line parameters
func (CmdParameterName) String ¶
func (c CmdParameterName) String() string
type Config ¶
type Config struct {
Log LogConfig `json:"log" toml:"log" yaml:"log"`
Dots []MetaLivesConfig `json:"dots" toml:"dots" yaml:"dots"`
}
Config config
func (*Config) FindConfig ¶
func (c *Config) FindConfig(typeID TypeID, liveID LiveID) *LiveConfig
FindConfig find config
type ConfigTypeLive ¶ added in v0.2.0
type ConfigTypeLive struct {
TypeIDConfig TypeID `json:"typeId"`
ConfigInfo interface{} `json:"json"`
}
ConfigTypeLive config json
type Creator ¶
type Creator interface {
//Create When this method is initializing, running or monitoring same content, better to realize it in Start method
Create(l Line) error
}
Creator create interface
type Destroyer ¶
type Destroyer interface {
//Destroy Dot
//ignore When calling other Lifer, if true erred will continue, if false erred will return directly
Destroy(ignore bool) error
}
Destroyer destroy interface
type Error ¶
type Error struct {
NilParameter Errorer
Existed Errorer
NotExisted Errorer
Parameter Errorer
RelyTypeNotMatch Errorer
TypeIDEmpty Errorer
Config Errorer
NoDotNewer Errorer
NotStruct Errorer
DotInvalid Errorer
}
Error dot error
type Eventer ¶
type Eventer interface {
//
ReSetLiveEvents(lid LiveID, liveEvents *LiveEvents)
//
AddLiveEvents(lid LiveID, liveEvents *LiveEvents)
//
LiveEvents(lid LiveID) []LiveEvents
//
ReSetTypeEvents(tid TypeID, typeEvents *TypeEvents)
//
AddTypeEvents(tid TypeID, typeEvents *TypeEvents)
//
TypeEvents(tid TypeID) []TypeEvents
}
Eventer event interface
type Events ¶
type Events struct {
//Before the dot create
BeforeCreate Event
//after the dot create
AfterCreate Event
//Before the dot start
BeforeStart Event
//After the dot start
AfterStart Event
//Before the dot stop
BeforeStop Event
//After the dot stop
AfterStop Event
//Before the dot destroy
BeforeDestroy Event
//After the dot destroy
AfterDestroy Event
}
Events dot events
type GetInterfaceType ¶ added in v0.2.0
GetInterfaceType return the interface of dot
type HotConfig ¶
type HotConfig interface {
//Update Update config info, return true means successful
HotConfig(newConf SConfig) bool
}
HotConfig hot change config
type Injecter ¶
type Injecter interface {
//Inject inject
//obj only support structure
//dot.TagDot (dot) tag is in the field
//If tag is empty, then input with field type, otherwise input with tag value(dot.LiveID)
//In the process if error occurred, it will not quit, returned error is the first one occurred
Inject(obj interface{}) error
//GetByType get by type
//If no related object in current container, then will call parent to search
//type container is seperate with liveid container
GetByType(t reflect.Type) (d Dot, err error)
//GetByLiveID get by liveid
//If no related object in current container, then will call parent to search
//type container is seperate with liveid container
GetByLiveID(id LiveID) (d Dot, err error)
//ReplaceOrAddByType update
//Cannot operate parent
ReplaceOrAddByType(d Dot) error
//Cannot operate parent
ReplaceOrAddByParamType(d Dot, t reflect.Type) error
//ReplaceOrAddByLiveID update
//Cannot operate parent
ReplaceOrAddByLiveID(d Dot, id LiveID) error
//RemoveByType remove
RemoveByType(t reflect.Type) error
//RemoveByLiveID remove
RemoveByLiveID(id LiveID) error
//SetParent set parent injecter
SetParent(p Injecter)
//GetParent get parent injecter
GetParent() Injecter
}
Injecter inject interface
type Lifer ¶
Lifer life cycle Create, Start,Stop,Destroy Create and Start are separate, in order to resolve the dependencies between different dot instances, if there is no problem with the dependencies, then you can directly null in Start All methods of Lifer cannot be stucked while running, now the realization of line is sync call
type Line ¶
type Line interface {
//Return unique Line name
ID() string
//Line API
Config() *Config
//SConfig general config API
SConfig() SConfig
SLogger() SLogger
//order
//1,Search liveid corresponding newer
//2,Search typid corresponding newer
//3,Search right newer in meta
//AddNewerByLiveID add new for liveid
AddNewerByLiveID(liveID LiveID, newDot Newer) error
//AddNewerByTypeID add new for type
AddNewerByTypeID(typeID TypeID, newDot Newer) error
//RemoveNewerByLiveID remove
RemoveNewerByLiveID(liveID LiveID)
//RemoveNewerByTypeID remove
RemoveNewerByTypeID(typeID TypeID)
//PreAdd Add dot liveid and meta info, here no dot is created, it will be generated after Computing dependence
//If it is the single sample, don't need to point sample info, sample id is typeid
//If config file has config sample, then it will be added automatically, if sample id already existing, then config is prior
PreAdd(typeLives ...*TypeLives) error
//relyOrder Check whether dependency existing
//relyOrder() error
////CreateDots create dots
//CreateDots() error
//ToLifer to lifer
ToLifer() Lifer
//ToInjecter to injecter
ToInjecter() Injecter
//ToDotEventer to Eventer
ToDotEventer() Eventer
//GetDotConfig get
GetDotConfig(liveID LiveID) *LiveConfig
GetLineBuilder() *Builder
//InfoAllTypeAdnLives just for debug, log info all types and lives
InfoAllTypeAdnLives()
//EachLives for each Lives, if the func return false, break the loop
EachLives(func(*Live, *Metadata) bool)
//DestroyConfigLog destroy config and log
DestroyConfigLog() error
}
Line line
func GetDefaultLine ¶
func GetDefaultLine() Line
GetDefaultLine Return default Line,general program only has one line
type Live ¶
type Live struct {
TypeID TypeID `json:"typeId"`
LiveID LiveID `json:"liveId"`
RelyLives map[string]LiveID `json:"relyLives"`
Dot Dot `json:"-"`
}
Live live/instance
type LiveConfig ¶
type LiveConfig struct {
//LiveID
LiveID LiveID `json:"liveId" toml:"liveId" yaml:"liveId"`
//RelyLives rely lives, If cannot confirm key value then key value is livid value
RelyLives map[string]LiveID `json:"relyLives" toml:"relyLives" yaml:"relyLives"`
//dot config
//todo tag
Config interface{} `json:"json" toml:"json" yaml:"json" mapstructure:"json"`
}
LiveConfig live config
type LogConfig ¶
type LogConfig struct {
DirPath string `json:"dirPath" toml:"dirPath" yaml:"dirPath"` // 文件夹路径
File string `json:"file" toml:"file" yaml:"file"` // 日志文件名
Level string `json:"level" toml:"level" yaml:"level"`
Time string `json:"time" toml:"time" yaml:"time"` //hour,h,day,d,month,m,y,year
MaxSize int `json:"maxSize" toml:"maxSize" yaml:"maxSize"` // 日志单文件,大小上限 最少:120M
MaxBackups int `json:"maxBackups" toml:"maxBackups" yaml:"maxBackups"` // 日志文件,最多有多少个 default:10
MaxAge int `json:"maxAge" toml:"maxAge" yaml:"maxAge"` // 日志文件保存时长 最少:30days
IsOpenConsole bool `json:"isOpenConsole" toml:"isOpenConsole" yaml:"isOpenConsole"` // 是否输出到控制台
}
LogConfig log config
type MetaLivesConfig ¶ added in v0.2.0
type MetaLivesConfig struct {
MetaData Metadata `json:"metaData" toml:"metaData" yaml:"metaData"`
Lives []LiveConfig `json:"lives" toml:"lives" yaml:"lives"`
}
MetaLivesConfig dot config
type Metadata ¶
type Metadata struct {
TypeID TypeID `json:"typeId"`
Version string `json:"version"`
Name string `json:"name"`
ShowName string `json:"showName"`
Single bool `json:"single"`
RelyTypeIDs []TypeID `json:"relyTypeIds"`
NewDoter Newer `json:"-"`
RefType reflect.Type `json:"-"` //if the dot is interface, set the type of interface
}
Metadata dot metadata
type SConfig ¶
type SConfig interface {
//RootPath root path
RootPath()
//Config file path
ConfigPath() string
//Without path, only file name
ConfigFile() string
//Whether key existing
Key(key string) bool
//If no config or config is empty, return nil
Map() (m map[string]interface{}, err error)
//Priorly bring data from RAM and operate, if RAM is nil then check whether original config file existing
Unmarshal(s interface{}) error
//Analyze key is corresponding type
UnmarshalKey(key string, obj interface{}) error
Marshal(data []byte) error
//If no corresponding key or data type cannot be converted, must pay attention to default value,
//so add "Def" before function to notify default value
DefInterface(key string, def interface{}) interface{}
DefArray(key string, def []interface{}) []interface{}
DefMap(key string, def map[string]interface{}) map[string]interface{}
DefString(key string, def string) string
DefInt32(key string, def int32) int32
DefUint32(key string, def uint32) uint32
DefInt64(key string, def int64) int64
DefUint64(key string, def uint64) uint64
DefBool(key string, def bool) bool
DefFloat32(key string, def float32) float32
DefFloat64(key string, def float64) float64
}
SConfig config belongs to one component Dot, but it is so basic, every Dot need it, so define it in dot.go file S represents scryinfo config this name is used frequently, so add s to distinguish it
type SLogger ¶
type SLogger interface {
//GetLevel get level
GetLevel() Level
//SetLevel set level
SetLevel(level Level)
//Debugln debug
Debugln(msg string, fields ...zap.Field)
//Debug debug
Debug(mstr MakeStringer)
//Infoln info
Infoln(msg string, fields ...zap.Field)
//Info info
Info(mstr MakeStringer)
//Warnln warn
Warnln(msg string, fields ...zap.Field)
//Warn warn
Warn(mstr MakeStringer)
//Errorln error
Errorln(msg string, fields ...zap.Field)
//Error error
Error(mstr MakeStringer)
//Fatalln fatal
Fatalln(msg string, fields ...zap.Field)
//Fatal fatal
Fatal(mstr MakeStringer)
//NewLogger return new logger
NewLogger(callerSkip int) SLogger
}
SLogger log belongs to one component Dot, but it is too basic, most Dot need it, so defined it to dot.go file All log calling should not call function in parameters, function run priorly than log, if must call function, you should use callback(must run normally) S represents scry info, log name used frequently so add s to distinguish it
func Logger ¶
func Logger() SLogger
Logger Return default log, this API is used to call log easily This method does not consider thread security, Adjusting value is not suggested after program initialization Note: Default log, if log is not created, then returned log will be output to control panel, all log will be output
type SetterLine ¶
type SetterLine interface {
SetLine(l Line)
}
SetterLine If component need to know current line, then realize this API, and this API Will be called before component Create
type SetterTypeAndLiveID ¶ added in v0.2.0
SetterTypeAndLiveID If component need to know current TypeID or LiveID, then realize this API, and this API Will be called before component Create
type Starter ¶
type Starter interface {
//ignore When calling other Lifer, if true erred will continue, if false erred will return directly
Start(ignore bool) error
}
Starter start interface
type Stopper ¶
type Stopper interface {
//ignore When calling other Lifer, if true erred will continue, if false erred will return directly
Stop(ignore bool) error
}
Stopper stop interface
type StringFromEnv ¶ added in v0.2.3
type StringFromEnv string
func (*StringFromEnv) UnmarshalYAML ¶ added in v0.2.3
func (e *StringFromEnv) UnmarshalYAML(value *yaml.Node) error
type Tager ¶
type Tager interface {
//SetTag set tag
SetTag(tag interface{})
//GetTag get tag
GetTag() (tag interface{})
}
Tager dot signature data, used by dot