Documentation ¶
Overview ¶
Package config handles the application configuration through environment variables and command line flags. It uses github.com/ardanlabs/conf for parsing configuration values into strongly typed configuration structs. All environment variables are prefixed with "SKD_" automatically.
Configuration can be provided via environment variables or command line flags. Command line flags take precedence over environment variables.
Example usage:
cfg, err := config.Load() if err != nil { if err.Error() == "help requested" { fmt.Println(err) os.Exit(0) } log.Fatal(err) } // Access configuration values fmt.Printf("Running in %s environment\n", cfg.Environment) fmt.Printf("Database host: %s:%d\n", cfg.Postgres.Host, cfg.Postgres.Port)
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( BuildBranch = "local" BuildRevision = "dev" BuildDate = "2006-01-02T15:04:05Z07:00" )
View Source
var ErrHelpWanted = errors.New("help requested")
ErrHelpWanted indicates that the --help flag was passed to the binary
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { conf.Version Core Postgres Observability }
type Core ¶
type Core struct { // Current deployment hostname. Hostname string `conf:"hostname,env:HOSTNAME"` // EncryptionKey used to encrypt all paste data. EncryptionKey string `conf:"encryption-key,env:ENCRYPTION_KEY"` // EncryptionSalt used to encrypt all paste data. EncryptionSalt string `conf:"encryption-salt,env:ENCRYPTION_SALT"` // Environment the application is running in. Environment string `conf:"env,env:ENVIRONMENT,default:dev"` }
type Observability ¶
type Postgres ¶
type Postgres struct { // Host where the postgres db can be reached at. Host string `conf:"host,env:POSTGRES_HOST"` // Port where the database is listening in. Port int `conf:"port,env:POSTGRES_PORT,default:5432"` // User to use for database queries. User string `conf:"user,env:POSTGRES_USER"` // Password for the db user. Password string `conf:"pass,env:POSTGRES_PASS"` // Database the application should connect to. Database string `conf:"db,env:POSTGRES_DB"` // URL is the full postgres connection URL in the format: postgres://user:pass@host:port/db URL string `conf:"url,env:POSTGRES_DB_URL"` }
Click to show internal directories.
Click to hide internal directories.