Load config from file with defaults

This commit is contained in:
Dan Jones 2024-02-04 18:19:19 -06:00
commit 40f9518611
8 changed files with 127 additions and 2 deletions

31
config/default.go Normal file
View file

@ -0,0 +1,31 @@
package config
import (
"fmt"
"os"
fp "path/filepath"
"github.com/BurntSushi/toml"
)
const ConfigStr = `
[input]
ext = "txt"
recurse = true
path = "%s"
[output]
[output.stdout]
enabled = true
[output.stdout.config]
json = false
`
func DefaultConfig() (Config, error) {
home, _ := os.UserHomeDir()
inDir := fp.Join(home, "my-log")
s := fmt.Sprintf(ConfigStr, inDir)
c := Config{}
_, err := toml.Decode(s, &c)
return c, err
}