kdhcp/config/path.go

40 lines
814 B
Go
Raw Normal View History

2023-05-02 16:27:27 +00:00
package config
import (
"os"
"os/user"
"path/filepath"
2023-05-05 07:13:46 +00:00
log "git.wntrmute.dev/kyle/goutils/syslog"
2023-05-02 16:27:27 +00:00
)
func FindConfigPath() string {
paths := []string{"/home/kyle/code/kdhcp/kdhcpd.yaml"}
user, err := user.Current()
if err == nil {
if homedir := user.HomeDir; homedir != "" {
2023-05-02 23:33:14 +00:00
paths = append(paths, filepath.Join(homedir, "code", "kdhcp", "kdhcpd.yaml"))
2023-05-02 16:27:27 +00:00
paths = append(paths, filepath.Join(homedir, ".config", "kdhcp", "kdhcpd.yaml"))
}
}
paths = append(paths, "/etc/kdhcp/kdhcpd.yaml")
for _, path := range paths {
2023-05-02 23:33:14 +00:00
log.Debugf("config: looking for config file at %s", path)
2023-05-02 16:27:27 +00:00
_, err = os.Stat(path)
if os.IsNotExist(err) {
continue
}
if err != nil {
log.Debugf("config: while trying to stat config file at '%s': %s", path, err)
continue
}
return path
}
return ""
}