config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFileName = "conf.toml"

Variables

This section is empty.

Functions

func BindEnv

func BindEnv(binders ...Binder) error

BindEnv executes any number of Binder functions and returns the first error.

func LoadConfigFromEnv

func LoadConfigFromEnv(config *Config) error

func LoadDatabaseFromEnv

func LoadDatabaseFromEnv(conf *Database) error

func LoadMailerFromEnv

func LoadMailerFromEnv(conf *Mailer) error

Types

type Binder

type Binder func() error

func BindField

func BindField[T any](ptr *T, field string, parserCallback func(string) T) Binder

func BindFieldErr

func BindFieldErr[T any](ptr *T, field string, parserCallback func(string) (T, error)) Binder

type Config

type Config struct {
	IsDebug     bool     `toml:"is_debug"`
	ProjectName string   `toml:"project_name"`
	Runtime     Runtime  `toml:"server"`
	Database    Database `toml:"database"`
	Mailer      Mailer   `toml:"mailer"`
}

func DefaultConfig

func DefaultConfig() Config

func Load

func Load(filename string) (Config, error)

Load loads the configuration using filename as the TOML file path. If the CONF_FILE environment variable is set it takes precedence over the filename argument. A missing file is not treated as an error. Environment variables are always overlaid on top of the loaded file.

func LoadTOML

func LoadTOML(paths ...string) (config Config, err error)

type Database

type Database struct {
	Host     string        `toml:"host"`
	Port     uint16        `toml:"port"`
	User     string        `toml:"user"`
	Password string        `toml:"password"`
	Database string        `toml:"database"`
	Timeout  time.Duration `toml:"timeout"`
}

type Mailer

type Mailer struct {
	Driver   string        `toml:"driver"` // "smtp", "webhook", or "stub"
	From     string        `toml:"from"`
	FromName string        `toml:"from_name"`
	Smtp     MailerSmtp    `toml:"smtp"`
	Webhook  MailerWebhook `toml:"webhook"`
}

type MailerSmtp

type MailerSmtp struct {
	Host       string `toml:"host"`
	Port       uint16 `toml:"port"`
	User       string `toml:"user"`
	Password   string `toml:"password"`
	Encryption string `toml:"encryption"` // "tls", "ssl", or "none"
}

type MailerWebhook

type MailerWebhook struct {
	URL    string `toml:"url"`
	APIKey string `toml:"api_key"`
}

type Runtime

type Runtime struct {
	APILocale     string `toml:"api_locale"`
	Host          string `toml:"host"`
	Port          uint16 `toml:"port"`
	AuthSecretKey string `toml:"auth_secret_key"`
}

Jump to

Keyboard shortcuts

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