config

package
v0.0.0-...-eca6f23 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvLocal   Environment = "local"
	EnvTest    Environment = "test"
	EnvDev     Environment = "dev"
	EnvStaging Environment = "staging"
	EnvLT      Environment = "lt"
	EnvQA      Environment = "qa"
	EnvProd    Environment = "prod"

	StorageLocal    Storage = "local"
	StorageDynamoDB Storage = "dynamodb"

	LvlDbg  LogLevel = "debug"
	LvlInfo LogLevel = "info"
	LvlWarn LogLevel = "warn"
	LvlErr  LogLevel = "error"
)

Variables

This section is empty.

Functions

func SwitchEnvironment

func SwitchEnvironment(env Environment)

SwitchEnvironment sets the environment variable used to dictate which environment the application is currently running in. This must be called prior to loading the configuration in order for it to take effect.

Types

type AWS

type AWS struct {
	AccessKeyID string `env:"AWS_ACCESS_KEY_ID"`
	Secret      string `env:"AWS_SECRET_ACCESS_KEY"`
	Region      string `env:"AWS_REGION"`
	Endpoint    string `env:"AWS_ENDPOINT"`
	AWSCfg      aws.Config
}

AWS defines the configs related to AWS services.

type App

type App struct {
	Name        string        `env:"APP_NAME,default=backfill"`
	Environment Environment   `env:"APP_ENVIRONMENT,default=local"`
	LogLevel    LogLevel      `env:"LOG_LEVEL,default=info"`
	Timeout     time.Duration `env:"APP_TIMEOUT,default=20s"`
	Storage     Storage       `env:"APP_STORAGE,default=local"`
}

App defines the configs needed for the application itself.

type Config

type Config struct {
	App
	HTTP
	Metrics
	AWS
	DynamoDB
}

Config is the aggregation of all necessary configurations.

func New

func New() (Config, error)

New loads the configuration based on the environment variables.

func (*Config) Validate

func (c *Config) Validate() error

type DynamoDB

type DynamoDB struct {
	ItemTable string `env:"DYNAMODB_ITEM_TABLE"`
}

DynamoDB defines the configs related specfically to the DynamoDB service.

type Environment

type Environment string

type HTTP

type HTTP struct {
	Hostname     string        `env:"HTTP_HOSTNAME,default=0.0.0.0"`
	Port         uint16        `env:"HTTP_PORT,default=8000"`
	ReadTimeout  time.Duration `env:"HTTP_READ_TIMEOUT,default=5s"`
	WriteTimeout time.Duration `env:"HTTP_WRITE_TIMEOUT,default=10s"`
	IdleTimeout  time.Duration `env:"HTTP_IDLE_TIMEOUT,default=2m"`
	TLS          struct {
		Enabled     bool   `env:"HTTP_TLS_ENABLED,default=false"`
		Certificate string `env:"HTTP_TLS_CERTIFICATE"`
		Key         string `env:"HTTP_TLS_KEY"`
	}
}

HTTP stores the configuration for the HTTP server.

type LogLevel

type LogLevel string

type Metrics

type Metrics struct {
	Enabled bool   `env:"METRICS_ENABLED,default=false"`
	Addr    string `env:"METRICS_ADDRESS"`
	BufLen  int    `env:"METRICS_BUFFER,default=5"`
}

Metrics defines the configs needed for collecting metrics.

type Storage

type Storage string

Jump to

Keyboard shortcuts

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