config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SQLite3Dialect represents the DB Dialect for SQLite3
	SQLite3Dialect = DBDialect("sqlite3")
	// MySQLDialect represents the DB Dialect for MySQL
	MySQLDialect = DBDialect("mysql")
	// ConfigFilename is the default config file name
	ConfigFilename = "webhook-broker.cfg"
	// DefaultSystemConfigFilePath is the default system location of the configuration
	DefaultSystemConfigFilePath = "/etc/webhook-broker/" + ConfigFilename
	// DefaultCurrentDirConfigFilePath is the config file path based on current working dir
	DefaultCurrentDirConfigFilePath = ConfigFilename
	// 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
)
View Source
const DefaultConfiguration = `` /* 1094-byte string literal not displayed */

DefaultConfiguration is the configuration that will be in effect if no configuration is loaded from any of the expected locations

Variables

View Source
var (
	// EmptyConfigurationForError Represents the configuration instance to be
	// used when there is a configuration error during load
	EmptyConfigurationForError = &Config{}

	// ConfigInjector sets up configuration related bindings
	ConfigInjector = wire.NewSet(GetConfigurationFromCLIConfig, wire.Bind(new(SeedDataConfig), new(*Config)), wire.Bind(new(HTTPConfig), new(*Config)), wire.Bind(new(RelationalDatabaseConfig), new(*Config)), wire.Bind(new(LogConfig), new(*Config)), wire.Bind(new(BrokerConfig), new(*Config)), wire.Bind(new(ConsumerConnectionConfig), new(*Config)))
)

Functions

This section is empty.

Types

type AppVersion

type AppVersion string

AppVersion is the version string type

func GetVersion

func GetVersion() AppVersion

GetVersion provides the current version of the project

type BrokerConfig

type BrokerConfig interface {
	GetMaxMessageQueueSize() uint
	GetMaxWorkers() uint
	IsPriorityDispatcherEnabled() bool
	GetRetriggerBaseEndpoint() string
	GetMaxRetry() uint8
	GetRationalDelay() time.Duration
	GetRetryBackoffDelays() []time.Duration
	IsRecoveryWorkersEnabled() bool
}

BrokerConfig provides the interface for configuring the broker

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

func (conf *CLIConfig) IsConfigWatcherStarted() bool

IsConfigWatcherStarted returns whether config watcher is running

func (*CLIConfig) IsMigrationEnabled

func (conf *CLIConfig) IsMigrationEnabled() bool

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
	SeedData                  SeedData
	TokenRequestHeaderName    string
	UserAgent                 string
	ConnectionTimeout         time.Duration
	MaxMessageQueueSize       uint
	MaxWorkers                uint
	PriorityDispatcherEnabled bool
	RecoveryWorkersEnabled    bool
	RetriggerBaseEndpoint     string
	MaxRetry                  uint8
	RationalDelay             time.Duration
	RetryBackoffDelays        []time.Duration
	LogLevel                  LogLevel
}

Config represents the application configuration

func GetAutoConfiguration

func GetAutoConfiguration() (*Config, error)

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

func GetConfiguration(configFilePath string) (*Config, error)

GetConfiguration gets the current state of application configuration

func GetConfigurationFromCLIConfig

func GetConfigurationFromCLIConfig(cliConfig *CLIConfig) (*Config, error)

GetConfigurationFromCLIConfig from CLIConfig.

func GetConfigurationFromParseConfig

func GetConfigurationFromParseConfig(cfg *ini.File) (*Config, error)

GetConfigurationFromParseConfig returns configuration from parsed configuration

func (*Config) GetConnectionTimeout

func (config *Config) GetConnectionTimeout() time.Duration

GetConnectionTimeout returns the connection timeout from broker to consumer

func (*Config) GetDBConnectionMaxIdleTime

func (config *Config) GetDBConnectionMaxIdleTime() time.Duration

GetDBConnectionMaxIdleTime returns the DB Connection max idle time

func (*Config) GetDBConnectionMaxLifetime

func (config *Config) GetDBConnectionMaxLifetime() time.Duration

GetDBConnectionMaxLifetime returns the DB Connection max lifetime

func (*Config) GetDBConnectionURL

func (config *Config) GetDBConnectionURL() string

GetDBConnectionURL returns the DB Connection URL string

func (*Config) GetDBDialect

func (config *Config) GetDBDialect() DBDialect

GetDBDialect returns the DB dialect of the configuration

func (*Config) GetHTTPListeningAddr

func (config *Config) GetHTTPListeningAddr() string

GetHTTPListeningAddr retrieves the connection string to listen to

func (*Config) GetHTTPReadTimeout

func (config *Config) GetHTTPReadTimeout() time.Duration

GetHTTPReadTimeout retrieves the connection read timeout

func (*Config) GetHTTPWriteTimeout

func (config *Config) GetHTTPWriteTimeout() time.Duration

GetHTTPWriteTimeout retrieves the connection write timeout

func (*Config) GetLogFilename

func (config *Config) GetLogFilename() string

GetLogFilename retrieves the file name of the log

func (*Config) GetLogLevel

func (config *Config) GetLogLevel() LogLevel

GetLogLevel returns the log level as per the configuration

func (*Config) GetMaxAgeForALogFile

func (config *Config) GetMaxAgeForALogFile() uint

GetMaxAgeForALogFile retrieves maximum day to retain a rotated log file

func (*Config) GetMaxIdleDBConnections

func (config *Config) GetMaxIdleDBConnections() uint16

GetMaxIdleDBConnections returns the maximum number of idle DB connections to retain in pool

func (*Config) GetMaxLogBackups

func (config *Config) GetMaxLogBackups() uint

GetMaxLogBackups retrieves max rotated logs to retain

func (*Config) GetMaxLogFileSize

func (config *Config) GetMaxLogFileSize() uint

GetMaxLogFileSize retrieves the max log file size before its rotated in MB

func (*Config) GetMaxMessageQueueSize

func (config *Config) GetMaxMessageQueueSize() uint

GetMaxMessageQueueSize returns the maximum number of messages to be queued without being dispatched

func (*Config) GetMaxOpenDBConnections

func (config *Config) GetMaxOpenDBConnections() uint16

GetMaxOpenDBConnections returns the maximum number of concurrent DB connections to keep open

func (*Config) GetMaxRetry

func (config *Config) GetMaxRetry() uint8

GetMaxRetry returns the maximum number of attempts for delivering a message to a consumer

func (*Config) GetMaxWorkers

func (config *Config) GetMaxWorkers() uint

GetMaxWorkers returns the max number of workers dispatching a message to a consumer

func (*Config) GetRationalDelay

func (config *Config) GetRationalDelay() time.Duration

GetRationalDelay returns how long to wait before retriggering, i.e., what is the addition to picking up messages in fail-safe process.

func (*Config) GetRetriggerBaseEndpoint

func (config *Config) GetRetriggerBaseEndpoint() string

GetRetriggerBaseEndpoint returns the URL to the load balanced endpoint for the broker for retriggering jobs

func (*Config) GetRetryBackoffDelays

func (config *Config) GetRetryBackoffDelays() []time.Duration

GetRetryBackoffDelays returns the delay steps in retrying delivery; retry will be the index and if index is greater than size use the last value times retry-attempt

func (*Config) GetSeedData

func (config *Config) GetSeedData() SeedData

GetSeedData returns the seed data configuration

func (*Config) GetTokenRequestHeaderName

func (config *Config) GetTokenRequestHeaderName() string

GetTokenRequestHeaderName returns the Token request header to pass to the consumers

func (*Config) GetUserAgent

func (config *Config) GetUserAgent() string

GetUserAgent returns the user agent string for consumer HTTP connection

func (*Config) IsCompressionEnabledOnLogBackups

func (config *Config) IsCompressionEnabledOnLogBackups() bool

IsCompressionEnabledOnLogBackups checks if log backups are compressed

func (*Config) IsLoggerConfigAvailable

func (config *Config) IsLoggerConfigAvailable() bool

IsLoggerConfigAvailable checks is logger configuration is set since its optional

func (*Config) IsPriorityDispatcherEnabled

func (config *Config) IsPriorityDispatcherEnabled() bool

IsPriorityDispatcherEnabled returns whether priority will be respected during dispatching from queue

func (*Config) IsRecoveryWorkersEnabled

func (config *Config) IsRecoveryWorkersEnabled() bool

IsRecoveryWorkersEnabled retrieves whether the recovery worker should be enabled or not

type ConsumerConnectionConfig

type ConsumerConnectionConfig interface {
	GetTokenRequestHeaderName() string
	GetUserAgent() string
	GetConnectionTimeout() time.Duration
}

ConsumerConnectionConfig provides the interface for working with consumer connection related configuration

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

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

type SeedChannel

type SeedChannel SeedProducer

SeedChannel represents pre configured channel via configuration

type SeedConsumer

type SeedConsumer struct {
	SeedProducer
	// CallbackURL represents the URl to call back
	CallbackURL *url.URL
	// Channels represents which channel this consumer listens to
	Channel string
}

SeedConsumer represents pre configured consumer via configuration

type SeedData

type SeedData struct {
	DataHash  string
	Producers []SeedProducer
	Channels  []SeedChannel
	Consumers []SeedConsumer
}

SeedData represents data specified in configuration to ensure is present when app starts up

func (*SeedData) Scan

func (u *SeedData) Scan(value interface{}) (err error)

Scan de-serializes SeedData for reading from DB

func (SeedData) Value

func (u SeedData) Value() (driver.Value, error)

Value serializes SeedData to write to DB

type SeedDataConfig

type SeedDataConfig interface {
	GetSeedData() SeedData
}

SeedDataConfig provides the interface for working with SeedData in configuration

type SeedProducer

type SeedProducer struct {
	// ID is the ID of the data
	ID string
	// Name is name of the data
	Name string
	// Token is the pre configured token of the data
	Token string
}

SeedProducer represents the pre configured producer via configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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