Skip to content

Commit

Permalink
internal/config: globalize config path
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Aug 22, 2023
1 parent 621d575 commit d8a894f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

//go:embed config.toml
var DefaultConfig string
var Path = filepath.Join(dirs.Config, "config.toml")

type Environment map[string]string

Expand All @@ -38,18 +39,16 @@ type Config struct {
func Load() Config {
var cfg Config

path := filepath.Join(dirs.Config, "config.toml")

// This is a default hard-coded configuration. It should not fail.
_, _ = toml.Decode(DefaultConfig, &cfg)

if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
if _, err := os.Stat(Path); errors.Is(err, os.ErrNotExist) {
log.Println("Using default configuration")

return cfg
}

if _, err := toml.DecodeFile(path, &cfg); err != nil {
if _, err := toml.DecodeFile(Path, &cfg); err != nil {
log.Printf("Failed to load configuration: %s, using default configuration", err)
}

Expand Down

0 comments on commit d8a894f

Please sign in to comment.