From 2bf38473893b4fcd86ce7c97c04846237bb8cce4 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Sun, 25 Jan 2026 16:32:21 +0100 Subject: feat(config): create file if not found at path --- common/config.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'common/config.go') 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) } -- cgit v1.2.3