Documentation ¶
Index ¶
- Variables
- func GetLoadFunc(defaultConfig, configFilename, systemPathPrefix, userHomePathPrefix string) func(string) (*ini.File, error)
- type CLIConfig
- type Config
- func (config *Config) GetDBConnectionMaxIdleTime() time.Duration
- func (config *Config) GetDBConnectionMaxLifetime() time.Duration
- func (config *Config) GetDBConnectionURL() string
- func (config *Config) GetDBDialect() DBDialect
- func (config *Config) GetHTTPListeningAddr() string
- func (config *Config) GetHTTPReadTimeout() time.Duration
- func (config *Config) GetHTTPWriteTimeout() time.Duration
- func (config *Config) GetLogFilename() string
- func (config *Config) GetLogLevel() LogLevel
- func (config *Config) GetMaxAgeForALogFile() uint
- func (config *Config) GetMaxIdleDBConnections() uint16
- func (config *Config) GetMaxLogBackups() uint
- func (config *Config) GetMaxLogFileSize() uint
- func (config *Config) GetMaxOpenDBConnections() uint16
- func (config *Config) IsCompressionEnabledOnLogBackups() bool
- func (config *Config) IsLoggerConfigAvailable() bool
- type DBDialect
- type HTTPConfig
- type LogConfig
- type LogLevel
- type RelationalDatabaseConfig
Constants ¶
This section is empty.
Variables ¶
var ( // EmptyConfigurationForError Represents the configuration instance to be // used when there is a configuration error during load EmptyConfigurationForError = &Config{} // ConfigFilename is the default file name when nothing is provided ConfigFilename = "appconfig.cfg" // DefaultConfiguration is the configuration that will be in effect if no configuration is loaded from any of the expected locations DefaultConfiguration = `` /* 343-byte string literal not displayed */ // DefaultLoadFunc defines DefaultLoadFunc = GetLoadFunc(DefaultConfiguration, ConfigFilename, "/etc/appconfig/", "/.appconfig/") LoadConfiguration = DefaultLoadFunc )
var ( ParseCLIArgs = func(programName string, args []string) (cliConfig *CLIConfig, output string, err error) { flags := flag.NewFlagSet(programName, flag.ContinueOnError) var buf bytes.Buffer flags.SetOutput(&buf) var conf CLIConfig flags.StringVar(&conf.ConfigPath, "config", "", "Config file location") flags.StringVar(&conf.MigrationSource, "migrate", "", "Migration source folder") flags.BoolVar(&conf.StopOnConfigChange, "stop-on-conf-change", false, "Restart internally on -config change if this flag is absent") flags.BoolVar(&conf.DoNotWatchConfigChange, "do-not-watch-conf-change", false, "Do not watch config change") err = flags.Parse(args) if err != nil { return nil, buf.String(), err } if len(conf.MigrationSource) > 0 { fileInfo, err := os.Stat(conf.MigrationSource) if err != nil { return nil, "Could not determine migration source details", err } if !fileInfo.IsDir() { return nil, "Migration source must be a dir", errMigrationSrcNotDir } if !filepath.IsAbs(conf.MigrationSource) { conf.MigrationSource, _ = filepath.Abs(conf.MigrationSource) } conf.MigrationSource = "file://" + conf.MigrationSource } return &conf, buf.String(), nil } )
Functions ¶
Types ¶
type CLIConfig ¶
type CLIConfig struct { ConfigPath string MigrationSource string StopOnConfigChange bool DoNotWatchConfigChange bool // contains filtered or unexported fields }
CLIConfig represents the Command Line Args config
func (*CLIConfig) IsConfigWatcherStarted ¶
IsConfigWatcherStarted returns whether config watcher is running
func (*CLIConfig) IsMigrationEnabled ¶
IsMigrationEnabled returns whether migration is enabled
func (*CLIConfig) NotifyOnConfigFileChange ¶
func (conf *CLIConfig) NotifyOnConfigFileChange(callback func())
NotifyOnConfigFileChange registers a callback function for changes to ConfigPath; it calls the `callback` when a change is detected
func (*CLIConfig) StopWatcher ¶
func (conf *CLIConfig) StopWatcher()
StopWatcher stops any watcher if started for CLI ConfigPath file change
type Config ¶
type Config struct { DBDialect DBDialect DBConnectionURL string DBConnectionMaxIdleTime time.Duration DBConnectionMaxLifetime time.Duration DBMaxIdleConnections uint16 DBMaxOpenConnections uint16 HTTPListeningAddr string HTTPReadTimeout time.Duration HTTPWriteTimeout time.Duration LogFilename string MaxFileSize uint MaxBackups uint MaxAge uint CompressBackupsEnabled bool LogLevel LogLevel }
Config represents the application configuration
func GetAutoConfiguration ¶
GetAutoConfiguration gets configuration from default config and system defined path chain of /etc/webhook-broker/webhook-broker.cfg, {USER_HOME}/.webhook-broker/webhook-broker.cfg, webhook-broker.cfg (current dir)
func GetConfiguration ¶
GetConfiguration gets the current state of application configuration
func GetConfigurationFromCLIConfig ¶
GetConfigurationFromCLIConfig from CLIConfig.
func GetConfigurationFromParseConfig ¶
GetConfigurationFromParseConfig returns configuration from parsed configuration
func (*Config) GetDBConnectionMaxIdleTime ¶
GetDBConnectionMaxIdleTime returns the DB Connection max idle time
func (*Config) GetDBConnectionMaxLifetime ¶
GetDBConnectionMaxLifetime returns the DB Connection max lifetime
func (*Config) GetDBConnectionURL ¶
GetDBConnectionURL returns the DB Connection URL string
func (*Config) GetDBDialect ¶
GetDBDialect returns the DB dialect of the configuration
func (*Config) GetHTTPListeningAddr ¶
GetHTTPListeningAddr retrieves the connection string to listen to
func (*Config) GetHTTPReadTimeout ¶
GetHTTPReadTimeout retrieves the connection read timeout
func (*Config) GetHTTPWriteTimeout ¶
GetHTTPWriteTimeout retrieves the connection write timeout
func (*Config) GetLogFilename ¶
GetLogFilename retrieves the file name of the log
func (*Config) GetLogLevel ¶
GetLogLevel returns the log level as per the configuration
func (*Config) GetMaxAgeForALogFile ¶
GetMaxAgeForALogFile retrieves maximum day to retain a rotated log file
func (*Config) GetMaxIdleDBConnections ¶
GetMaxIdleDBConnections returns the maximum number of idle DB connections to retain in pool
func (*Config) GetMaxLogBackups ¶
GetMaxLogBackups retrieves max rotated logs to retain
func (*Config) GetMaxLogFileSize ¶
GetMaxLogFileSize retrieves the max log file size before its rotated in MB
func (*Config) GetMaxOpenDBConnections ¶
GetMaxOpenDBConnections returns the maximum number of concurrent DB connections to keep open
func (*Config) IsCompressionEnabledOnLogBackups ¶
IsCompressionEnabledOnLogBackups checks if log backups are compressed
func (*Config) IsLoggerConfigAvailable ¶
IsLoggerConfigAvailable checks is logger configuration is set since its optional
type DBDialect ¶
type DBDialect string
DBDialect allows us to define constants for supported DB drivers
type HTTPConfig ¶
type HTTPConfig interface { GetHTTPListeningAddr() string GetHTTPReadTimeout() time.Duration GetHTTPWriteTimeout() time.Duration }
HTTPConfig represents the HTTP configuration related behaviors
type LogConfig ¶
type LogConfig interface { GetLogLevel() LogLevel IsLoggerConfigAvailable() bool GetLogFilename() string GetMaxLogFileSize() uint GetMaxLogBackups() uint GetMaxAgeForALogFile() uint IsCompressionEnabledOnLogBackups() bool }
LogConfig represents the interface for log related configuration
type LogLevel ¶
type LogLevel uint8
LogLevel represents the log level logger should use
const ( // SQLite3Dialect represents the DB Dialect for SQLite3 SQLite3Dialect = DBDialect("sqlite3") // MySQLDialect represents the DB Dialect for MySQL MySQLDialect = DBDialect("mysql") // Debug is the lowest LogLevel, will expose all logs Debug LogLevel = 20 + iota // Info is the second lowest LogLevel Info // Error is the second highest LogLevel Error // Fatal is the highest LogLevel with lowest logs Fatal )
type RelationalDatabaseConfig ¶
type RelationalDatabaseConfig interface { GetDBDialect() DBDialect GetDBConnectionURL() string GetDBConnectionMaxIdleTime() time.Duration GetDBConnectionMaxLifetime() time.Duration GetMaxIdleDBConnections() uint16 GetMaxOpenDBConnections() uint16 }
RelationalDatabaseConfig represents DB configuration related behaviors