✨ Load config from file with defaults
This commit is contained in:
parent
2da9fcac37
commit
40f9518611
8 changed files with 127 additions and 2 deletions
31
config/default.go
Normal file
31
config/default.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue