✨ Write config file
This commit is contained in:
parent
a6f3cf39a0
commit
3546c1d7f6
2 changed files with 76 additions and 7 deletions
|
|
@ -8,23 +8,36 @@ import (
|
|||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
const ConfigStr = `
|
||||
[input]
|
||||
ext = "txt"
|
||||
recurse = true
|
||||
path = "%s"
|
||||
const ConfigStr = `# Configuration for my-log
|
||||
|
||||
[input]
|
||||
# Path to where the log files are stored
|
||||
path = "%s"
|
||||
# File extension for log files
|
||||
ext = "txt"
|
||||
# Whether to look in sub-folders
|
||||
recurse = true
|
||||
|
||||
# config for output types
|
||||
[output]
|
||||
|
||||
# This one just prints the logs to stdout when run
|
||||
[output.stdout]
|
||||
enabled = true
|
||||
[output.stdout.config]
|
||||
# Whether to output as JSON. Maybe useful to pipe elsewhere.
|
||||
json = false
|
||||
|
||||
`
|
||||
|
||||
func DefaultConfig() (Config, error) {
|
||||
func DefaultStr() string {
|
||||
home, _ := os.UserHomeDir()
|
||||
inDir := fp.Join(home, "my-log")
|
||||
s := fmt.Sprintf(ConfigStr, inDir)
|
||||
return fmt.Sprintf(ConfigStr, inDir)
|
||||
}
|
||||
|
||||
func DefaultConfig() (Config, error) {
|
||||
s := DefaultStr()
|
||||
c := Config{}
|
||||
_, err := toml.Decode(s, &c)
|
||||
return c, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue