Documentation
¶
Index ¶
- Constants
- func CheckRunInTestEnvironment() bool
- type Config
- type Flag
- type Properties
- func (p Properties) GetOrDie(key string) interface{}
- func (p Properties) GetStringOrDefault(key string, dlft string) string
- func (p Properties) GetSubOrDie(key string) *viper.Viper
- func (props *Properties) LoadModeProperties(panicOnModeLoad bool) *Properties
- func (p Properties) TryLoadRemoteProperties()
- type RemoteProvider
Constants ¶
const ( // Default config type DefaultConfigType = "json" // Default config file name DefaultConfigName = "app" // Default config storage directory DefaultConfigDir = "" // Default config mode DefaultConfigMode = "prod" // Default test config mode spelling DefaultTestModeTag = "test" )
const ( ConfigNameTag = "config-name" ConfigDirTag = "config-dir" ModeTag = "mode" ConfigTypeTag = "config-type" )
Flags Tag referrer e.g. ConfigNameTag imply => myexec --config-name "xxx"
Variables ¶
This section is empty.
Functions ¶
func CheckRunInTestEnvironment ¶
func CheckRunInTestEnvironment() bool
CheckRunInTestEnvironment return true if this application is running with 'go test'
Types ¶
type Config ¶
type Config struct {
// Define the config files type for K/V stores, allowed types are :
// ["json", "toml", "yaml", "yml", "properties", "props", "prop"]
// Default: json
ConfigType string
// Define to Environement variables to look up
EnvVars []string
// Define the name of config files (without extension) to look up for.
// Default: "config"
ConfigName string
// Define the pathes where to lookup for config files
ConfigPathes []string
// Define the remote provides names:
Providers []RemoteProvider
// Define the flags to lookup for
Flags []Flag
// Overridable Mode Tag to use for test session by default set to DefaultTestModeTag
TestModeTag string
// Overridable default mode
DefaultConfigMode string
}
Config is a struct that allows to initialize the Properties type with user defined values
func DefaultConfig ¶
func DefaultConfig() (c Config)
DefaultConfig return a default configuration with Flags and Env already set...
func (Config) GetDefaultModeProperties ¶
func (c Config) GetDefaultModeProperties() *Properties
GetDefaultModeProperties get A Default Property set for classic app based on Flag with Config file : app.json in current directory from Flag With HOME and PWD from env
func (*Config) InitConfig ¶
func (c *Config) InitConfig()
InitConfig init config with default value if not set
type Flag ¶
type Flag struct {
// Flag Name used in command line
Name string
// When gives the default flag value
Default string
// Usage string shown in the help
Usage string
}
Flag is a struct that stores flags configuration
type Properties ¶
Properties is a struct that allow to handle application properties seting and acessing. It wraps spf13/viper library
func New ¶
func New(config ...Config) *Properties
Properties constructor Settings default values if need
func (Properties) GetOrDie ¶
func (p Properties) GetOrDie(key string) interface{}
GetOrDie get key, if not found panic
func (Properties) GetStringOrDefault ¶
func (p Properties) GetStringOrDefault(key string, dlft string) string
GetStringOrDefault get string or a default value
func (Properties) GetSubOrDie ¶
func (p Properties) GetSubOrDie(key string) *viper.Viper
GetOrDie get key, if not found panic
func (*Properties) LoadModeProperties ¶
func (props *Properties) LoadModeProperties(panicOnModeLoad bool) *Properties
Helper to Load Properties and merge it with mode related Properties path will be use by default if user not provide a ConfigDirTag in command line defaultMode will be use by default if user not provide a ModeTag in command line props is used as properties base. panicOnModeLoad if true, when loading mode properties failed call "panic" otherwise "warning"
func (Properties) TryLoadRemoteProperties ¶
func (p Properties) TryLoadRemoteProperties()
TryLoadRemoteProperties try load configuration from remote througth Viper
type RemoteProvider ¶
type RemoteProvider struct {
// Set the provider's name | must be "ectd" or "consul"
Name string
// Set the provider's url : "http://ip:port" for "etcd", "ip:port" for "consul"
Url string
// Set the path in the k/v store to retrieve configuration
Path string
// If set check the remote provider with encryption using the defined keyFile
KeyFile string
}
Privider is a struct that hold remote providers data
