2026-04-08 12:31:09 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
|
Server ServerConfig `yaml:"server"`
|
|
|
|
|
VeriFactu VeriFactuConfig `yaml:"verifactu"`
|
|
|
|
|
Certificates CertificateConfig `yaml:"certificates"`
|
|
|
|
|
Crypto CryptoConfig `yaml:"crypto"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ServerConfig struct {
|
|
|
|
|
Port int `yaml:"port"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type VeriFactuConfig struct {
|
|
|
|
|
Environment string `yaml:"environment"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CertificateConfig struct {
|
|
|
|
|
StoragePath string `yaml:"storage_path"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CryptoConfig struct {
|
|
|
|
|
KeysPath string `yaml:"keys_path"`
|
2026-04-08 12:35:16 +00:00
|
|
|
Name string `yaml:"name"`
|
|
|
|
|
Email string `yaml:"email"`
|
2026-04-08 12:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Load(path string) (*Config, error) {
|
|
|
|
|
data, err := os.ReadFile(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("reading config file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cfg Config
|
|
|
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("parsing config file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if cfg.Server.Port == 0 {
|
|
|
|
|
cfg.Server.Port = 8080
|
|
|
|
|
}
|
|
|
|
|
if cfg.VeriFactu.Environment == "" {
|
|
|
|
|
cfg.VeriFactu.Environment = "test"
|
|
|
|
|
}
|
|
|
|
|
if cfg.Certificates.StoragePath == "" {
|
|
|
|
|
cfg.Certificates.StoragePath = "./certs/"
|
|
|
|
|
}
|
|
|
|
|
if cfg.Crypto.KeysPath == "" {
|
|
|
|
|
cfg.Crypto.KeysPath = "./keys/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &cfg, nil
|
|
|
|
|
}
|