Documentation
¶
Index ¶
- func Init(flagSet *flag.FlagSet, cfg Configurator, options ...Option) error
- func IsExitError(err error) (code int, ok bool)
- func Read(cfg Configurator, optional bool) error
- type BaseConfig
- type Configurator
- type CoreConfig
- type Discoverable
- type DiscoveryConfig
- type LogConfig
- type MQConfig
- type Mode
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(flagSet *flag.FlagSet, cfg Configurator, options ...Option) error
Init initializes Configure cfg from command line flags with options
func IsExitError ¶
func Read ¶ added in v0.0.18
func Read(cfg Configurator, optional bool) error
Types ¶
type BaseConfig ¶
type BaseConfig struct { // Core represents core common fields Core CoreConfig `json:"core"` // contains filtered or unexported fields }
BaseConfig implments Configurator
func (*BaseConfig) GetCore ¶ added in v0.0.18
func (c *BaseConfig) GetCore() *CoreConfig
GetCore implements Configurator GetCore method
func (*BaseConfig) GetSource ¶ added in v0.0.18
func (c *BaseConfig) GetSource() string
GetSource implements Configurator GetSource method
func (*BaseConfig) OnReload ¶ added in v0.0.18
func (c *BaseConfig) OnReload()
func (*BaseConfig) Read ¶
func (c *BaseConfig) Read(self Configurator, r io.Reader) error
Read implements Configurator Read method
func (*BaseConfig) SetSource ¶
func (c *BaseConfig) SetSource(source string)
SetSource implements Configurator SetSource method
func (BaseConfig) Write ¶
func (c BaseConfig) Write(self Configurator, w io.Writer) error
Write implements Configurator Write method
type Configurator ¶
type Configurator interface { // Read reads config from reader r Read(Configurator, io.Reader) error // Write writes config to writer w Write(Configurator, io.Writer) error // GetSource returns source of config GetSource() string // SetSource sets source of config SetSource(string) // GetCore returns core configuration GetCore() *CoreConfig // Default returns default configuration Default() Configurator // OnReload fired after configuration reloaded OnReload() }
Configurator represents generic config of application
type CoreConfig ¶ added in v0.0.18
type CoreConfig struct { Project string `json:"project"` Mode Mode `json:"mode"` Name string `json:"name"` ID int64 `json:"id"` Log LogConfig `json:"log"` MQ MQConfig `json:"mq"` Discovery DiscoveryConfig `json:"discovery"` }
Core configuration
type Discoverable ¶
type Discoverable interface {
// DiscoveredContent returns a discovered data
DiscoveredContent() interface{}
}
Discoverable represents a discoverable configurator
type DiscoveryConfig ¶
type DiscoveryConfig struct { Off bool `json:"off"` Name string `json:"name"` Source string `json:"source"` }
DiscoveryConfig ...
type LogConfig ¶
type LogConfig struct { // Prefix to preappend to each log message Prefix string `json:"prefix"` // Level of log, reload supported Level string `json:"level"` // Flags of log printer, reload supported // @see githug.com/gopherd/log@Flags. // -1: no flags // 0: default flags Flags int `json:"flags"` // Writers specified multi-writers, like: // [ // "console", // "file:path/to/filename?suffix=.txt" // ] Writers []string `json:"writers"` }
LogConfig represents configuration of log
func (LogConfig) FixedFlags ¶ added in v0.0.18
type MQConfig ¶
type MQConfig struct { Off bool `json:"off"` Name string `json:"name"` Source string `json:"source"` }
MQConfig ...
type Mode ¶
type Mode int
Process running mode
func (Mode) MarshalJSON ¶
MarshalJSON implements json.Marshaler MarshalJSON method
func (*Mode) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler UnmarshalJSON method
type Option ¶
type Option func(*option)
Option is the option for Init
func WithDefaultSource ¶
WithDefaultSource specify default config source
func WithOutput ¶
WithOutput specify command line flag name and usage for config output
func WithVersion ¶
WithVersion specify command line flag name and usage for version