config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Service    ServiceConfig
	HttpServer HttpServerConfig
	//HttpClient HttpClientConfig
	Database DatabaseConfig
}

func GetConfig

func GetConfig(configFileDirName string) *Config

Returns config from a file or environment variables. Env vars have priority if they exist.

type DatabaseConfig

type DatabaseConfig struct {
	Hostname string `toml:"host" env:"DB_HOSTNAME" env-required`
	Port     int    `toml:"port" env:"DB_PORT" env-required`
	Instance string `toml:"instance" env:"DB_INSTANCE"`
	DBName   string `toml:"dbname" env:"DB_NAME" env-required`
	User     string `toml:"user" env:"DB_USER" env-required`
	Password string `toml:"password" env:"DB_PASSWORD" env-required`
}

type HttpServerConfig

type HttpServerConfig struct {
	Hostname          string          `toml:"hostname" env:"HTTPSERVER_HOSTNAME" env-required`
	HostPort          int             `toml:"host_port" env:"HTTPSERVER_HOST_PORT" env-required`
	ReadHeaderTimeout StrTimeDuration `toml:"read_header_timeout_duration" env:"HTTPSERVER_READ_HEADER_TIMEOUT_DURATION" env-required`
	WriteTimeout      StrTimeDuration `toml:"write_timeout_duration" env:"HTTPSERVER_WRITE_TIMEOUT_DURATION" env-required`
}

type ServiceConfig

type ServiceConfig struct {
	JWTSigningSecretKey string `toml:"jwt_signing_secret_key" env:"AUTH_JWT_SIGNING_SECRET_KEY" env-required`

	JWTEncryptionSecretKey string `toml:"jwt_encryption_secret_key" env:"AUTH_JWT_ENCRYPTION_SECRET_KEY" env-required`

	JWTExpirationDuration StrTimeDuration `toml:"jwt_expiration_time_duration" env:"AUTH_JWT_EXPIRATION_TIME_DURATION"`
}

type StrTimeDuration

type StrTimeDuration string

Purpose: 1) Reap the benefit of being able to use time duration string format in config variables. 2) Validate format when parsing the config file / env var and not having to do it always before passing each value of the type to a builder or contructor func.

func (*StrTimeDuration) GetDuration

func (d *StrTimeDuration) GetDuration() time.Duration

func (*StrTimeDuration) SetValue

func (d *StrTimeDuration) SetValue(s string) error

Implements Setter interface needed by library cleanenv to set the custom type

Jump to

Keyboard shortcuts

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