Documentation ¶
Overview ¶
Package env represents environment services abstraction layer. It provides a set of interfaces and helpers to make application input/output operations and messaging behind scenes.
For a meantime package consists of:
- configuration service
- ini file service
- error bus
- event bus
- logger
Index ¶
- Constants
- func ConfigEmptyValueValidator(val interface{}) (interface{}, bool)
- func ConfigGetValue(Path string) interface{}
- func Error(module string, level int, code string, message string) error
- func ErrorCode(err error) string
- func ErrorDispatch(err error) error
- func ErrorLevel(err error) int
- func ErrorMessage(err error) string
- func ErrorModify(err error, module string, level int, code string) error
- func ErrorNew(module string, level int, code string, message string) error
- func ErrorRaw(message string) error
- func ErrorRegisterListener(listener FuncErrorListener)
- func Event(event string, args map[string]interface{})
- func EventRegisterListener(event string, listener FuncEventListener)
- func IniValue(Path string) string
- func Log(storage string, prefix string, message string)
- func LogError(err error)
- func LogEvent(f LogFields, eventName string)
- func OnConfigIniStart() error
- func OnConfigStart() error
- func RegisterConfig(Config InterfaceConfig) error
- func RegisterErrorBus(errorBus InterfaceErrorBus) error
- func RegisterEventBus(eventBus InterfaceEventBus) error
- func RegisterIniConfig(IniConfig InterfaceIniConfig) error
- func RegisterLogger(logger InterfaceLogger) error
- func RegisterOnConfigIniStart(callback func() error)
- func RegisterOnConfigStart(callback func() error)
- func RegisterScheduler(scheduler InterfaceScheduler) error
- func TypeArrayOf(dataType string) string
- func TypeIsArray(dataType string) bool
- func TypeIsFloat(dataType string) bool
- func TypeIsString(dataType string) bool
- func TypeParse(typeName string) utils.DataType
- func TypeWPrecision(dataType string, precision int) string
- func TypeWPrecisionAndScale(dataType string, precision int, scale int) string
- type FuncConfigValueValidator
- type FuncCronTask
- type FuncErrorListener
- type FuncEventListener
- type InterfaceConfig
- type InterfaceErrorBus
- type InterfaceEventBus
- type InterfaceIniConfig
- type InterfaceLogger
- type InterfaceOttemoError
- type InterfaceSchedule
- type InterfaceScheduler
- type LogFields
- type StructConfigItem
Constants ¶
const ( ConstConfigTypeID = utils.ConstDataTypeID ConstConfigTypeBoolean = utils.ConstDataTypeBoolean ConstConfigTypeVarchar = utils.ConstDataTypeVarchar ConstConfigTypeText = utils.ConstDataTypeText ConstConfigTypeInteger = utils.ConstDataTypeInteger ConstConfigTypeDecimal = utils.ConstDataTypeDecimal ConstConfigTypeMoney = utils.ConstDataTypeMoney ConstConfigTypeFloat = utils.ConstDataTypeFloat ConstConfigTypeDatetime = utils.ConstDataTypeDatetime ConstConfigTypeJSON = utils.ConstDataTypeJSON ConstConfigTypeHTML = utils.ConstDataTypeHTML ConstConfigTypeGroup = "group" ConstConfigTypeSecret = "secret" ConstLogPrefixError = "ERROR" ConstLogPrefixWarning = "WARNING" ConstLogPrefixDebug = "DEBUG" ConstLogPrefixInfo = "INFO" ConstErrorLevelAPI = 10 ConstErrorLevelModel = 9 ConstErrorLevelActor = 8 ConstErrorLevelHelper = 7 ConstErrorLevelService = 4 ConstErrorLevelServiceAct = 3 ConstErrorLevelCritical = 2 ConstErrorLevelStartStop = 1 ConstErrorLevelExternal = 0 ConstErrorModule = "env" ConstErrorLevel = ConstErrorLevelService )
Package global constants
Variables ¶
This section is empty.
Functions ¶
func ConfigEmptyValueValidator ¶
func ConfigEmptyValueValidator(val interface{}) (interface{}, bool)
ConfigEmptyValueValidator is a default validator function to accept any value
func ConfigGetValue ¶
func ConfigGetValue(Path string) interface{}
ConfigGetValue returns config value or nil if not present
func ErrorDispatch ¶
ErrorDispatch handles error, returns new one you should pass next
func ErrorModify ¶
ErrorModify works similar to ErrorDispatch but allows to set error level, code and module name
func ErrorRaw ¶
ErrorRaw creates new error by parsing given string (seek for module name, level and code inside) and dispatches it
func ErrorRegisterListener ¶
func ErrorRegisterListener(listener FuncErrorListener)
ErrorRegisterListener registers listener for error bus
func EventRegisterListener ¶
func EventRegisterListener(event string, listener FuncEventListener)
EventRegisterListener registers listener for event bus
func OnConfigIniStart ¶
func OnConfigIniStart() error
OnConfigIniStart fires ini config service start event (callback handling)
func OnConfigStart ¶
func OnConfigStart() error
OnConfigStart fires config service start event (callback handling)
func RegisterConfig ¶
func RegisterConfig(Config InterfaceConfig) error
RegisterConfig registers config service in the system
- will cause error if there are couple candidates for that role
func RegisterErrorBus ¶
func RegisterErrorBus(errorBus InterfaceErrorBus) error
RegisterErrorBus registers error processor in the system
- will cause error if there are couple candidates for that role
func RegisterEventBus ¶
func RegisterEventBus(eventBus InterfaceEventBus) error
RegisterEventBus registers event processor in the system
- will cause error if there are couple candidates for that role
func RegisterIniConfig ¶
func RegisterIniConfig(IniConfig InterfaceIniConfig) error
RegisterIniConfig registers ini config service in the system
- will cause error if there are couple candidates for that role
func RegisterLogger ¶
func RegisterLogger(logger InterfaceLogger) error
RegisterLogger registers logging service in the system
- will cause error if there are couple candidates for that role
func RegisterOnConfigIniStart ¶
func RegisterOnConfigIniStart(callback func() error)
RegisterOnConfigIniStart registers new callback on ini configuration service start
func RegisterOnConfigStart ¶
func RegisterOnConfigStart(callback func() error)
RegisterOnConfigStart registers new callback on configuration service start
func RegisterScheduler ¶
func RegisterScheduler(scheduler InterfaceScheduler) error
RegisterScheduler registers scheduler in the system
- will cause error if there are couple candidates for that role
func TypeArrayOf ¶
TypeArrayOf shortcut for utils.DataTypeArrayOf
func TypeIsArray ¶
TypeIsArray shortcut for utils.DataTypeIsArray
func TypeIsFloat ¶
TypeIsFloat shortcut for utils.DataTypeIsFloat
func TypeIsString ¶
TypeIsString shortcut for utils.DataTypeIsString
func TypeWPrecision ¶
TypeWPrecision shortcut for utils.DataTypeWPrecision
Types ¶
type FuncConfigValueValidator ¶
type FuncConfigValueValidator func(interface{}) (interface{}, error)
FuncConfigValueValidator is a configuration value validator callback function prototype
type FuncCronTask ¶
FuncCronTask is a callback function prototype executes by scheduler
type FuncErrorListener ¶
FuncErrorListener is an error listener callback function prototype
type FuncEventListener ¶
FuncEventListener is an event listener callback function prototype
- return value is continue flag, so listener should return false to stop event propagation
type InterfaceConfig ¶
type InterfaceConfig interface { RegisterItem(Item StructConfigItem, Validator FuncConfigValueValidator) error UnregisterItem(Path string) error ListPathes() []string GetValue(Path string) interface{} SetValue(Path string, Value interface{}) error GetGroupItems() []StructConfigItem GetItemsInfo(Path string) []StructConfigItem Load() error Reload() error }
InterfaceConfig is an interface to configuration values managing service
func GetConfig ¶
func GetConfig() InterfaceConfig
GetConfig returns currently the used configuration service implementation or nil
type InterfaceErrorBus ¶
type InterfaceErrorBus interface { GetErrorLevel(error) int GetErrorCode(error) string GetErrorMessage(error) string RegisterListener(FuncErrorListener) Dispatch(err error) error Modify(err error, module string, level int, code string) error Prepare(module string, level int, code string, message string) error New(module string, level int, code string, message string) error Raw(message string) error }
InterfaceErrorBus is an interface to system error processor
func GetErrorBus ¶
func GetErrorBus() InterfaceErrorBus
GetErrorBus returns currently used error processor implementation or nil
type InterfaceEventBus ¶
type InterfaceEventBus interface { RegisterListener(event string, listener FuncEventListener) New(event string, eventData map[string]interface{}) }
InterfaceEventBus is an interface to system event processor
func GetEventBus ¶
func GetEventBus() InterfaceEventBus
GetEventBus returns currently used event processor implementation or nil
type InterfaceIniConfig ¶
type InterfaceIniConfig interface { SetWorkingSection(sectionName string) error SetValue(valueName string, value string) error GetSectionValue(sectionName string, valueName string, defaultValue string) string GetValue(valueName string, defaultValue string) string ListSections() []string ListItems() []string ListSectionItems(sectionName string) []string }
InterfaceIniConfig is an interface to startup configuration predefined values service
func GetIniConfig ¶
func GetIniConfig() InterfaceIniConfig
GetIniConfig returns currently used ini config service implementation or nil
type InterfaceLogger ¶
type InterfaceLogger interface { Log(storage string, prefix string, message string) LogError(err error) LogEvent(f LogFields, eventName string) }
InterfaceLogger is an interface to system logging service
func GetLogger ¶
func GetLogger() InterfaceLogger
GetLogger returns currently used logging service implementation or nil
type InterfaceOttemoError ¶
type InterfaceOttemoError interface { ErrorFull() string ErrorLevel() int ErrorCode() string ErrorMessage() string ErrorCallStack() string IsHandled() bool MarkHandled() bool IsLogged() bool MarkLogged() bool error }
InterfaceOttemoError is an interface to errors generated by error bus service
type InterfaceSchedule ¶
type InterfaceSchedule interface { Execute() RunTask(params map[string]interface{}) error Enable() error Disable() error Set(param string, value interface{}) error Get(param string) interface{} GetInfo() map[string]interface{} }
InterfaceSchedule is an interface to system schedule service
type InterfaceScheduler ¶
type InterfaceScheduler interface { ListTasks() []string RegisterTask(name string, task FuncCronTask) error ScheduleAtTime(scheduleTime time.Time, taskName string, taskParams map[string]interface{}) (InterfaceSchedule, error) ScheduleRepeat(cronExpr string, taskName string, taskParams map[string]interface{}) (InterfaceSchedule, error) ScheduleOnce(cronExpr string, taskName string, taskParams map[string]interface{}) (InterfaceSchedule, error) ListSchedules() []InterfaceSchedule }
InterfaceScheduler is an interface to system scheduler service
func GetScheduler ¶
func GetScheduler() InterfaceScheduler
GetScheduler returns currently used scheduler implementation or nil
Directories ¶
Path | Synopsis |
---|---|
Package config is a default implementation of InterfaceConfig declared in "github.com/ottemo/commerce/env" package.
|
Package config is a default implementation of InterfaceConfig declared in "github.com/ottemo/commerce/env" package. |
Package cron is a utility to schedule tasks.
|
Package cron is a utility to schedule tasks. |
Package errorbus is a default implementation of InterfaceErrorBus declared in "github.com/ottemo/commerce/env" package.
|
Package errorbus is a default implementation of InterfaceErrorBus declared in "github.com/ottemo/commerce/env" package. |
Package eventbus is a default implementation of InterfaceEventBus declared in "github.com/ottemo/commerce/env" package.
|
Package eventbus is a default implementation of InterfaceEventBus declared in "github.com/ottemo/commerce/env" package. |
Package ini is a default implementation of InterfaceIniConfig declared in "github.com/ottemo/commerce/env" package.
|
Package ini is a default implementation of InterfaceIniConfig declared in "github.com/ottemo/commerce/env" package. |
Package logger is a default implementation of InterfaceLogger declared in "github.com/ottemo/commerce/env" package.
|
Package logger is a default implementation of InterfaceLogger declared in "github.com/ottemo/commerce/env" package. |