54 lines
1.1 KiB
Go
54 lines
1.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"`
|
|
Defaults struct {
|
|
HomeTemplate string `yaml:"homeTemplate"`
|
|
Provider string `yaml:"provider"`
|
|
} `yaml:"defaults"`
|
|
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
|
|
}
|