summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index daf42fe..8c5aebf 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -5,6 +5,8 @@ import (
"fmt"
"os"
"path/filepath"
+
+ "github.com/BurntSushi/toml"
)
type Config struct {
@@ -42,6 +44,19 @@ func Default() (*Config, error) {
}, nil
}
+// LoadFile loads a TOML config file on top of the defaults.
+// Fields not present in the file retain their default values.
+func LoadFile(path string) (*Config, error) {
+ cfg, err := Default()
+ if err != nil {
+ return nil, err
+ }
+ if _, err := toml.DecodeFile(path, cfg); err != nil {
+ return nil, fmt.Errorf("loading config file %q: %w", path, err)
+ }
+ return cfg, nil
+}
+
// EnsureDirs creates the data directory structure.
func (c *Config) EnsureDirs() error {
for _, dir := range []string{c.DataDir, c.LogDir} {