config

package
v0.0.0-...-3288de0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RedactedValue = "*****"

Functions

This section is empty.

Types

type Config

type Config struct {
	Name      string `env:"APP_NAME"`
	ClientURL string `env:"APP_CLIENT_URL"`
	Port      int    `env:"APP_PORT" envDefault:"4000"`
	Env       string `env:"APP_ENV" envDefault:"development"`

	Mail     Mail     // Mail config
	Postgres Postgres // Postgres config
}

func New

func New() (Config, error)

Creates a new config from enviroment variables.

func (Config) Addr

func (c Config) Addr() string

Returns an addr in the ':<port>' format.

func (Config) Dump

func (c Config) Dump(w io.Writer) error

Dumps the current configuration to w in json format.

func (Config) IsDev

func (c Config) IsDev() bool

Checks if current env is 'development'.

func (Config) IsProd

func (c Config) IsProd() bool

Checks if current env is 'production'.

func (Config) SlogLevel

func (c Config) SlogLevel() slog.Level

Returns the appropriate slog.Level based on the current config.

type Mail

type Mail struct {
	Host     string   `env:"MAIL_HOST" envDefault:"localhost"`
	Port     int      `env:"MAIL_PORT" envDefault:"8025"`
	User     string   `env:"MAIL_USER"`
	Password Redacted `env:"MAIL_PASSWORD"`
	Sender   string   `env:"MAIL_DEFAULT_SENDER"`
}

type Postgres

type Postgres struct {
	Host     string   `env:"POSTGRES_HOST,required"`
	Port     int      `env:"POSTGRES_PORT,required"`
	User     string   `env:"POSTGRES_USER,required"`
	Password Redacted `env:"POSTGRES_PASSWORD,required"`
	DB       string   `env:"POSTGRES_DB,required"`
	SSLMode  string   `env:"POSTGRES_SSL_MODE" envDefault:"disable"`

	MaxOpenConns int           `env:"POSTGRES_MAX_OPEN_CONNS" envDefault:"25"`
	MaxIdleConns int           `env:"POSTGRES_MAX_OPEN_CONNS" envDefault:"25"`
	MaxIdleTime  time.Duration `env:"POSTGRES_MAX_IDLE_DURATION" envDefault:"15m"`
}

func (Postgres) DSN

func (pc Postgres) DSN() string

type Redacted

type Redacted string

Represents a sensitive string value. Will be marshaled to '*****' in json.

func (Redacted) MarshalJSON

func (r Redacted) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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