diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-01-25 16:32:21 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-01-25 16:32:21 +0100 |
| commit | 2bf38473893b4fcd86ce7c97c04846237bb8cce4 (patch) | |
| tree | b8a94fbe190b02e21fcc8d5d9634f140556aa475 /common | |
| parent | f84edf350c805d2e918441dc3a3102c951439fe1 (diff) | |
feat(config): create file if not found at path
Diffstat (limited to 'common')
| -rw-r--r-- | common/config.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/common/config.go b/common/config.go index 07cff8d..8cb74ab 100644 --- a/common/config.go +++ b/common/config.go @@ -56,9 +56,17 @@ func (c *Config) SetDefaultValues() { func LoadConfig(path string) (*Config, error) { b, err := os.ReadFile(path) + var cfg Config if err != nil { - return nil, err + if !os.IsNotExist(err) { + return nil, err + } + cfg.SetDefaultValues() + b, err := toml.Marshal(cfg) + if err != nil { + return nil, err + } + return nil, os.WriteFile(path, b, 0600) } - var cfg Config return &cfg, toml.Unmarshal(b, &cfg) } |
