env

package
v1.4.5-alpha1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2019 License: MPL-2.0 Imports: 3 Imported by: 76

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

View Source
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 Error

func Error(module string, level int, code string, message string) error

Error creates new error (without dispatch)

func ErrorCode

func ErrorCode(err error) string

ErrorCode returns error code of given error

func ErrorDispatch

func ErrorDispatch(err error) error

ErrorDispatch handles error, returns new one you should pass next

func ErrorLevel

func ErrorLevel(err error) int

ErrorLevel returns error level of given error

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage returns message of given error

func ErrorModify

func ErrorModify(err error, module string, level int, code string) error

ErrorModify works similar to ErrorDispatch but allows to set error level, code and module name

func ErrorNew

func ErrorNew(module string, level int, code string, message string) error

ErrorNew creates new error and dispatches it

func ErrorRaw

func ErrorRaw(message string) error

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 Event

func Event(event string, args map[string]interface{})

Event emits new event for registered listeners

func EventRegisterListener

func EventRegisterListener(event string, listener FuncEventListener)

EventRegisterListener registers listener for event bus

func IniValue

func IniValue(Path string) string

IniValue returns value from ini file or "" if not present

func Log

func Log(storage string, prefix string, message string)

Log logs general purpose message

func LogError

func LogError(err error)

LogError logs an error message

func LogEvent

func LogEvent(f LogFields, eventName string)

LogEvent is a Log function short form for info messages in default storage

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

func TypeArrayOf(dataType string) string

TypeArrayOf shortcut for utils.DataTypeArrayOf

func TypeIsArray

func TypeIsArray(dataType string) bool

TypeIsArray shortcut for utils.DataTypeIsArray

func TypeIsFloat

func TypeIsFloat(dataType string) bool

TypeIsFloat shortcut for utils.DataTypeIsFloat

func TypeIsString

func TypeIsString(dataType string) bool

TypeIsString shortcut for utils.DataTypeIsString

func TypeParse

func TypeParse(typeName string) utils.DataType

TypeParse shortcut for utils.DataTypeParse

func TypeWPrecision

func TypeWPrecision(dataType string, precision int) string

TypeWPrecision shortcut for utils.DataTypeWPrecision

func TypeWPrecisionAndScale

func TypeWPrecisionAndScale(dataType string, precision int, scale int) string

TypeWPrecisionAndScale shortcut for utils.DataTypeWPrecisionAndScale

Types

type FuncConfigValueValidator

type FuncConfigValueValidator func(interface{}) (interface{}, error)

FuncConfigValueValidator is a configuration value validator callback function prototype

type FuncCronTask

type FuncCronTask func(params map[string]interface{}) error

FuncCronTask is a callback function prototype executes by scheduler

type FuncErrorListener

type FuncErrorListener func(error) bool

FuncErrorListener is an error listener callback function prototype

type FuncEventListener

type FuncEventListener func(string, map[string]interface{}) bool

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

type LogFields

type LogFields map[string]interface{}

type StructConfigItem

type StructConfigItem struct {
	Path  string
	Value interface{}

	Type string

	Editor  string
	Options interface{}

	Label       string
	Description string

	Image string
}

StructConfigItem is a structure to hold information about particular configuration value

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL