load config from stdin
This commit is contained in:
parent
dee71ac90d
commit
515ffb9ab5
|
@ -20,4 +20,6 @@ type Config struct {
|
|||
HostEmail string // used for the thumbnail fetcher
|
||||
BaseURL string
|
||||
ThumbnailDir string
|
||||
|
||||
LogFile string // if unset it'll log to stdout
|
||||
}
|
||||
|
|
|
@ -33,13 +33,31 @@ func main() {
|
|||
conffile = os.Args[2]
|
||||
}
|
||||
|
||||
dat, err := os.ReadFile(conffile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
if conffile == "--" {
|
||||
dec := toml.NewDecoder(os.Stdin)
|
||||
err := dec.Decode(&acdform.Conf)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
} else {
|
||||
dat, err := os.ReadFile(conffile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
err = toml.Unmarshal(dat, &acdform.Conf)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
err = toml.Unmarshal(dat, &acdform.Conf)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
|
||||
var err error
|
||||
|
||||
if acdform.Conf.LogFile != "" {
|
||||
lfile, err := os.OpenFile(acdform.Conf.LogFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Default().SetOutput(lfile)
|
||||
}
|
||||
|
||||
if acdform.Conf.Submissions.DiscordWebhook != "" {
|
||||
|
|
Loading…
Reference in New Issue