mailout/pkg/config/config.go
Thomas Maurice 09d3149932
All checks were successful
build / build (push) Successful in 1m10s
Build and release / build (push) Successful in 14m51s
feat(mail): adds a test subcomand
2024-02-13 18:30:54 +01:00

51 lines
1 KiB
Go

package config
import (
"os"
providerConfigs "git.maurice.fr/thomas/mailout/pkg/providers/configs"
"gopkg.in/yaml.v3"
)
type Config struct {
Postgres struct {
Hostname string `yaml:"hostname"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
SSLMode string `yaml:"sslmode"`
} `yaml:"postgres"`
DefaultProvider string `yaml:"defaultProvider"`
Providers struct {
OVH *providerConfigs.OVHConfig `yaml:"ovh"`
} `yaml:"providers"`
Test *struct {
Address string `yaml:"address"`
Username string `yaml:"username"`
Password string `yaml:"password"`
} `yaml:"test"`
}
func LoadConfig(path string) (*Config, error) {
b, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var cfg Config
err = yaml.Unmarshal(b, &cfg)
if err != nil {
return nil, err
}
if cfg.Postgres.SSLMode == "" {
cfg.Postgres.SSLMode = "disable"
}
if cfg.Postgres.Port == 0 {
cfg.Postgres.Port = 5432
}
return &cfg, err
}