Documentation ¶
Index ¶
Constants ¶
View Source
const ( ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgConfig ErrorConfigMissingViper ErrorComponentNotFound ErrorComponentConfigNotFound ErrorComponentConfigError )
View Source
const ( MinErrorComponentHttp = ErrorParamsEmpty + 10 MinErrorComponentLog = MinErrorComponentHttp + 10 MinErrorComponentTls = MinErrorComponentLog + 10 )
Variables ¶
This section is empty.
Functions ¶
func IsCodeError ¶
func IsCodeError() bool
Types ¶
type Component ¶
type Component interface { // Type return the component type. Type() string // RegisterContext is called by Config to register a function to get the main context. // This function can be used into start / reload function to use context interface. RegisterContext(fct FuncContext) // RegisterGet is called by Config to register a function to get a component by his key. // This function can be used for dependencies into start / reload function. RegisterGet(fct FuncComponentGet) // RegisterFuncStartBefore is called to register a function to be called before the start function. RegisterFuncStartBefore(fct func() liberr.Error) // RegisterFuncStartAfter is called to register a function to be called after the start function. RegisterFuncStartAfter(fct func() liberr.Error) // RegisterFuncReloadBefore is called to register a function to be called before the reload function. RegisterFuncReloadBefore(fct func() liberr.Error) // RegisterFuncReloadAfter is called to register a function to be called after the reload function. RegisterFuncReloadAfter(fct func() liberr.Error) // Start is called by the Config interface when the global configuration as been started // This function can be usefull to start server in go routine with a configuration stored // itself. Start(getCpt FuncComponentGet, getCfg FuncComponentConfigGet) liberr.Error // IsStarted is trigger by the Config interface with function ComponentIsStarted. // This function can be usefull to know if the start server function is still call. IsStarted() bool // Reload is called by the Config interface when the global configuration as been updated // It receives a func as param to grab a config model by sending a model structure. // It must configure itself, and stop / start his server if possible or return an error. Reload(getCpt FuncComponentGet, getCfg FuncComponentConfigGet) liberr.Error // Stop is called by the Config interface when global context is done. // The context done can arrive by stopping the application or by received a signal KILL/TERM. // This function must stop cleanly the component. Stop() // IsRunning is trigger by the Config interface with function ComponentIsRunning. // This function can be usefully to know if the component server function is still call. // The atLeast param is used to know if the function must return true on first server is running // or if all server must be running to return true. IsRunning(atLeast bool) bool // DefaultConfig is called by Config.GetDefault. // It must return a slice of byte containing the default json config for this component. DefaultConfig() []byte // Dependencies is called by Config to define if this component need other component. // Each other component can be call by calling Config.Get Dependencies() []string }
type ComponentList ¶
type ComponentList interface { // ComponentHas return true if the key is a registered Component ComponentHas(key string) bool // ComponentType return the Component Type of the registered key. ComponentType(key string) string // ComponentGet return the given component associated with the config Key. // The component can be transTyped to other interface to be exploited ComponentGet(key string) Component // ComponentDel remove the given Component key from the config. ComponentDel(key string) // ComponentSet stores the given Component with a key. ComponentSet(key string, cpt Component) // ComponentList returns a map of stored couple keyType and Component ComponentList() map[string]Component // ComponentKeys returns a slice of stored Component keys ComponentKeys() []string // ComponentStart trigger the Start function of each Component. // This function will keep the dependencies of each Component. // This function will stop the Start sequence on any error triggered. ComponentStart(getCpt FuncComponentGet, getCfg FuncComponentConfigGet) liberr.Error // ComponentIsStarted will trigger the IsStarted function of all registered component. // If any component return false, this func return false. ComponentIsStarted() bool // ComponentReload trigger the Reload function of each Component. // This function will keep the dependencies of each Component. // This function will stop the Reload sequence on any error triggered. ComponentReload(getCpt FuncComponentGet, getCfg FuncComponentConfigGet) liberr.Error // ComponentStop trigger the Stop function of each Component. // This function will not keep the dependencies of each Component. ComponentStop() // ComponentIsRunning will trigger the IsRunning function of all registered component. // If any component return false, this func return false. ComponentIsRunning(atLeast bool) bool // DefaultConfig aggregates all registered components' default config // Returns a filled buffer with a complete config json model DefaultConfig() io.Reader }
type Config ¶
type Config interface { // Context return the current context pointer Context() context.Context // ContextMerge trigger the golib/context/config interface // and will merge the stored context value into current context ContextMerge(ctx libctx.Config) bool // ContextStore trigger the golib/context/config interface // and will store a context value into current context ContextStore(key string, cfg interface{}) // ContextLoad trigger the golib/context/config interface // and will restore a context value or nil ContextLoad(key string) interface{} // ContextSetCancel allow to register a custom function called on cancel context. // On context cancel event or signal kill, term... this function will be called // before config stop and main context cancel function ContextSetCancel(fct func()) RegisterFuncViper(fct func() libvpr.Viper) // Start will trigger the start function of all registered component. // If any component return an error, this func will stop the start // process and return the error. Start() liberr.Error // RegisterFuncStartBefore allow to register a func to be call when the config Start // is trigger. This func is call before the start sequence. RegisterFuncStartBefore(fct func() liberr.Error) // RegisterFuncStartAfter allow to register a func to be call when the config Start // is trigger. This func is call after the start sequence. RegisterFuncStartAfter(fct func() liberr.Error) // Reload triggers the Reload function of each registered Component. Reload() liberr.Error // RegisterFuncReloadBefore allow to register a func to be call when the config Reload // is trigger. This func is call before the reload sequence. RegisterFuncReloadBefore(fct func() liberr.Error) // RegisterFuncReloadAfter allow to register a func to be call when the config Reload // is trigger. This func is call after the reload sequence. RegisterFuncReloadAfter(fct func() liberr.Error) // Stop will trigger the stop function of all registered component. // All component must stop cleanly. Stop() // RegisterFuncStopBefore allow to register a func to be call when the config Stop // is trigger. This func is call before the stop sequence. RegisterFuncStopBefore(fct func()) // RegisterFuncStopAfter allow to register a func to be call when the config Stop // is trigger. This func is call after the stop sequence. RegisterFuncStopAfter(fct func()) /* // Section Component : github.com/nabbar/golib/config */ ComponentList }
type FuncComponentConfigGet ¶
type FuncComponentGet ¶
type FuncContext ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.