config

package
v0.0.0-...-2dbaee0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 3 Imported by: 0

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
}

func Load

func Load() (Config, error)

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 Observability struct {
	Logging Otlp `conf:"logging"`
	Metrics Otlp `conf:"metrics"`
	Tracing Otlp `conf:"tracing"`
}

type Otlp

type Otlp struct {
	// Enabled controls if this otlp exporter should be used or not.
	Enabled bool `conf:"enabled"`
	// Host where the otlp collector can be reached at.
	Host string `conf:"host"`
	// Port where the otlp collector is listening in.
	Port int `conf:"port"`
}

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"`
}

Jump to

Keyboard shortcuts

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