feat: test multiple path for config

This commit is contained in:
Bastien Riviere 2023-09-01 19:11:02 +02:00
parent fa914c9e9c
commit 83c6fd9734
Signed by: babariviere
GPG key ID: 4E5F0839249F162E

22
main.go
View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
"net/http" "net/http"
@ -10,6 +11,27 @@ import (
"forge.babariviere.com/babariviere/ntfy-bridge/config" "forge.babariviere.com/babariviere/ntfy-bridge/config"
) )
// TODO: allow to pass config path
func readConfig() (config.Config, error) {
paths := []string{
"config.scfg",
// TODO: properly handle XDG_CONFIG
os.Getenv("HOME") + "/.config/ntfy-bridge/config.scfg",
os.Getenv("HOME") + "/.ntfy-bridge/config.scfg",
"/etc/ntfy-bridge/config.scfg",
}
for _, path := range paths {
if _, err := os.Stat(path); err != nil {
continue
}
return config.ReadConfig(path)
}
return config.Config{}, errors.New("no configuration file found")
}
func main() { func main() {
cfg, err := config.ReadConfig("config.scfg") cfg, err := config.ReadConfig("config.scfg")
if err != nil { if err != nil {