feat(init): First commit

This commit is contained in:
Thomas Maurice 2024-02-11 19:59:34 +01:00
commit f92368748a
Signed by: thomas
GPG key ID: 1D577F50583032A6
22 changed files with 1298 additions and 0 deletions

45
pkg/config/config.go Normal file
View file

@ -0,0 +1,45 @@
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"`
Providers struct {
OVH *providerConfigs.OVHConfig `yaml:"ovh"`
} `yaml:"providers"`
}
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
}