Documentation
¶
Index ¶
- Constants
- type Config
- type ConfigurationLoader
- type Db
- type DbType
- type Deployment
- type HTTPClientConfig
- type Instrumentation
- type Logging
- type Redis
- type Server
- type Swagger
- type ViperConfig
- func (c *ViperConfig) Load() *Config
- func (c *ViperConfig) WithDb() ConfigurationLoader
- func (c *ViperConfig) WithEnvironment(appName string) ConfigurationLoader
- func (c *ViperConfig) WithHTTPClient(name string) ConfigurationLoader
- func (c *ViperConfig) WithInstrumentation() ConfigurationLoader
- func (c *ViperConfig) WithLog() ConfigurationLoader
- func (c *ViperConfig) WithRedis() ConfigurationLoader
- func (c *ViperConfig) WithServer() ConfigurationLoader
- func (c *ViperConfig) WithSwagger() ConfigurationLoader
Constants ¶
const ( EnvServerPort = "server.port" EnvServerHost = "server.host" EnvServerTLSEnabled = "server.tls.enabled" EnvServerTLSCert = "server.tls.cert" EnvServerPprofEnabled = "server.pprof.enabled" EnvSwaggerHost = "swagger.host" EnvSwaggerEnabled = "swagger.enabled" EnvMetricsEnabled = "metrics.enabled" EnvTracingEnabled = "tracing.enabled" EnvEnvironment = "env.environment" EnvRegion = "env.region" EnvVersion = "env.version" EnvCommit = "env.commit" EnvBuildDate = "env.builddate" EnvLogLevel = "log.level" EnvDb = "db.type" EnvDbSchema = "db.schema.path" EnvDbDsn = "db.dsn" EnvDbMigrate = "db.migrate" EnvHTTPClientHost = "%s.client.host" EnvHTTPClientPort = "%s.client.port" EnvHTTPClientTimeout = "%s.client.timeout" EnvHTTPClientTLSEnabled = "%s.client.tls.enabled" EnvHTTPClientTLSCert = "%s.client.tls.cert" EnvRedisAddress = "redis.address" EnvRedisPassword = "redis.password" EnvRedisDb = "redis.db" LogDebug = "debug" LogInfo = "info" LogError = "error" LogWarn = "warn" )
Config keys used for goconfig, these get converted to UPPERCASE_SPLIT env vars.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Logging *Logging Server *Server Deployment *Deployment Db *Db Redis *Redis Swagger *Swagger Instrumentation *Instrumentation // contains filtered or unexported fields }
Config returns strongly typed config values.
func (*Config) CustomHTTPClient ¶
func (c *Config) CustomHTTPClient(name string) *HTTPClientConfig
CustomHTTPClient will return a custom http client, if not found nil is returned.
type ConfigurationLoader ¶
type ConfigurationLoader interface { WithServer() ConfigurationLoader WithEnvironment(appname string) ConfigurationLoader WithLog() ConfigurationLoader WithHTTPClient(name string) ConfigurationLoader WithDb() ConfigurationLoader WithRedis() ConfigurationLoader WithSwagger() ConfigurationLoader WithInstrumentation() ConfigurationLoader Load() *Config }
ConfigurationLoader will load configuration items into a struct that contains a configuration.
type Db ¶
Db contains database information.
func (*Db) Validate ¶
func (d *Db) Validate(v validator.ErrValidation) validator.ErrValidation
Validate will ensure the HeaderClient config is valid.
type Deployment ¶
type Deployment struct { Environment string AppName string Region string Version string Commit string BuildDate time.Time }
Deployment contains information relating to the current deployed instance.
func (*Deployment) IsDev ¶
func (d *Deployment) IsDev() bool
IsDev determines if this app is running on a dev environment.
func (*Deployment) String ¶
func (d *Deployment) String() string
String implements the stringer interface for printing.
type HTTPClientConfig ¶
type HTTPClientConfig struct { Host string Port string TLSEnabled bool TLSCert bool Timeout time.Duration }
HTTPClientConfig is a custom http client config struct, returned when CustomHTTPClient is called.
type Instrumentation ¶
type Instrumentation struct { // MetricsEnabled will enable / disable metric collection such as prometheus. MetricsEnabled bool // TracingEnabled will enable / disable open tracing. TracingEnabled bool }
Instrumentation contains metrics and tracing functionality.
type Logging ¶
type Logging struct {
Level string
}
Logging will set the default log level for the application.
type Server ¶
type Server struct { Port string Hostname string TLSCertPath string TLSEnabled bool PProfEnabled bool }
Server contains all settings required to run a web server.
type Swagger ¶
type Swagger struct { // Host, if set, will override the default swagger host which // is usually the same as the server hosting it ie 'localhost'. Host string // Enabled if true, can be used to switch swagger endpoints on. Enabled bool }
Swagger contains swagger configuration.
type ViperConfig ¶
type ViperConfig struct {
*Config
}
ViperConfig wraps config and implements ConfigurationLoader.
func NewViperConfig ¶
func NewViperConfig(appname string) *ViperConfig
NewViperConfig will setup and return viper configuration that implements goconfig.ConfigurationLoader.
func (*ViperConfig) Load ¶
func (c *ViperConfig) Load() *Config
Load will finish setup and return configuration. This should always be the last call.
func (*ViperConfig) WithDb ¶
func (c *ViperConfig) WithDb() ConfigurationLoader
WithDb sets up and returns database configuration.
func (*ViperConfig) WithEnvironment ¶
func (c *ViperConfig) WithEnvironment(appName string) ConfigurationLoader
WithEnvironment sets up the deployment configuration if required.
func (*ViperConfig) WithHTTPClient ¶
func (c *ViperConfig) WithHTTPClient(name string) ConfigurationLoader
WithHTTPClient will setup a custom http client referenced by name.
func (*ViperConfig) WithInstrumentation ¶
func (c *ViperConfig) WithInstrumentation() ConfigurationLoader
WithInstrumentation will read instrumentation environment vars.
func (*ViperConfig) WithLog ¶
func (c *ViperConfig) WithLog() ConfigurationLoader
WithLog sets up logger config from environment variables.
func (*ViperConfig) WithRedis ¶
func (c *ViperConfig) WithRedis() ConfigurationLoader
WithRedis will include redis config.
func (*ViperConfig) WithServer ¶
func (c *ViperConfig) WithServer() ConfigurationLoader
WithServer will setup the web server configuration if required.
func (*ViperConfig) WithSwagger ¶
func (c *ViperConfig) WithSwagger() ConfigurationLoader
WithSwagger will setup and return swagger configuration.