Documentation
¶
Index ¶
- Constants
- Variables
- func Load(ctx context.Context) error
- func NewContext(ctx context.Context, m Manager) context.Context
- func Register(name string, mgr Manager)
- type BoolType
- type ConfigMetaData
- type ConfigureValue
- func (c *ConfigureValue) GetAnyType() (interface{}, error)
- func (c *ConfigureValue) GetBool() bool
- func (c *ConfigureValue) GetFloat64() float64
- func (c *ConfigureValue) GetInt() int
- func (c *ConfigureValue) GetInt64() int64
- func (c *ConfigureValue) GetName() string
- func (c *ConfigureValue) GetPassword() string
- func (c *ConfigureValue) GetString() string
- func (c *ConfigureValue) GetStringToStringMap() map[string]string
- func (c *ConfigureValue) Set(name, value string) error
- func (c *ConfigureValue) Validate() error
- type Float64Type
- type Int64Type
- type IntType
- type Item
- type Manager
- type MapType
- type NonEmptyStringType
- type PasswordType
- type PortType
- type QuotaType
- type StringToStringMapType
- type StringType
- type Type
Constants ¶
const (
DBConfigManager = "config.manager.db"
)
Variables ¶
var ( // ErrorNotDefined ... ErrorNotDefined = errors.New("configure item is not defined in metadata") // ErrorTypeNotMatch ... ErrorTypeNotMatch = errors.New("the required value doesn't matched with metadata defined") // ErrorInvalidData ... ErrorInvalidData = errors.New("the data provided is invalid") // ErrorValueNotSet ... ErrorValueNotSet = errors.New("the configure value is not set") // ErrorStringValueIsEmpty ... ErrorStringValueIsEmpty = errors.New("the configure value can not be empty") )
var ( // DefaultCfgManager the default change manager, default is DBCfgManager. // If InMemoryConfigManager is used, need to set to InMemoryCfgManager in // test code. DefaultConfigManager = DBConfigManager )
Functions ¶
func NewContext ¶
NewContext returns context with CfgManager
Types ¶
type ConfigMetaData ¶
type ConfigMetaData struct {
// contains filtered or unexported fields
}
ConfigMetaData ...
func Instance ¶
func Instance() *ConfigMetaData
Instance - Get Instance, make it singleton because there is only one copy of metadata in an env
func (*ConfigMetaData) GetAll ¶
func (c *ConfigMetaData) GetAll() []Item
GetAll - Get all metadata in current env
func (*ConfigMetaData) GetByName ¶
func (c *ConfigMetaData) GetByName(name string) (*Item, bool)
GetByName - Get current metadata of current name, if not defined, return false in second params
func (*ConfigMetaData) InitFromArray ¶
func (c *ConfigMetaData) InitFromArray(items []Item)
initFromArray - Initial metadata from an array
func (*ConfigMetaData) Register ¶
func (c *ConfigMetaData) Register(name string, item Item)
Registe - append the item to metadata
type ConfigureValue ¶
type ConfigureValue struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}
func NewConfigureValue ¶
func NewConfigureValue(name, value string) (*ConfigureValue, error)
func (*ConfigureValue) GetAnyType ¶
func (c *ConfigureValue) GetAnyType() (interface{}, error)
GetAnyType get the interface{} of current value
func (*ConfigureValue) GetBool ¶
func (c *ConfigureValue) GetBool() bool
GetBool - return the bool value of current setting
func (*ConfigureValue) GetFloat64 ¶
func (c *ConfigureValue) GetFloat64() float64
GetFloat64 - return the float64 value of current value
func (*ConfigureValue) GetInt ¶
func (c *ConfigureValue) GetInt() int
GetInt - return the int value of current value
func (*ConfigureValue) GetInt64 ¶
func (c *ConfigureValue) GetInt64() int64
GetInt64 - return the int64 value of current value
func (*ConfigureValue) GetName ¶
func (c *ConfigureValue) GetName() string
func (*ConfigureValue) GetString ¶
func (c *ConfigureValue) GetString() string
func (*ConfigureValue) GetStringToStringMap ¶
func (c *ConfigureValue) GetStringToStringMap() map[string]string
GetStringToStringMap - return the string to string map of current value
func (*ConfigureValue) Set ¶
func (c *ConfigureValue) Set(name, value string) error
Set - set this configure item to configure store
func (*ConfigureValue) Validate ¶
func (c *ConfigureValue) Validate() error
Validate - to validate configure items, if passed, return nil, else return error
type Float64Type ¶
type Float64Type struct{}
type Item ¶
type Item struct {
// The Scope of this configuration item: eg: SystemScope, UserScope
Scope string `json:"scope,omitempty"`
// email, ldapbasic, ldapgroup, uaa settings, used to retieve configure items by group
Group string `json:"group,omitempty"`
// environment key to retrieves this value when initialize, for example: POSTGRESQL_HOST, only used for system settings, for user settings no EnvKey
EnvironmentKey string `json:"environment_key,omitempty"`
// The default string value for this key
DefaultValue string `json:"default_value,omitempty"`
// The key for current configure settings in database or rest api
Name string `json:"name,omitempty"`
// It can be &IntType{}, &StringType{}, &BoolType{}, &PasswordType{}, &MapType{} etc, any type interface implementation
ItemType Type
// Editable means it can updated by configure api, For system configure, the editable is always false, for user configure, it may depends
Editable bool `json:"editable,omitempty"`
// Description - Describle the usage of the configure item
Description string
}
Item - Configure item include default value, type, env name
type Manager ¶
type Manager interface {
Load(ctx context.Context) error
Set(ctx context.Context, key string, value interface{})
Save(ctx context.Context) error
Get(ctx context.Context, key string) *ConfigureValue
UpdateConfig(ctx context.Context, cfgs map[string]interface{}) error
GetUserConfigs(ctx context.Context) map[string]interface{}
ValidateConfig(ctx context.Context, cfgs map[string]interface{}) error
GetAll(ctx context.Context) map[string]interface{}
}
Manager defines the operation for config
func FromContext ¶
FromContext returns CfgManager from context
func GetConfigManager ¶
func GetManager ¶
GetManager get the configure manager by name