feat: test multiple path for config
This commit is contained in:
parent
fa914c9e9c
commit
83c6fd9734
1 changed files with 22 additions and 0 deletions
22
main.go
22
main.go
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue