cli.LoadConfig accepts config file now

This commit is contained in:
Jiang Zhu 2022-06-05 17:55:27 +08:00
parent adb55bcfe9
commit 0363e58467
3 changed files with 62 additions and 13 deletions

View file

@ -33,15 +33,19 @@ const (
HeadscaleDateTimeFormat = "2006-01-02 15:04:05"
)
func LoadConfig(path string) error {
viper.SetConfigName("config")
if path == "" {
viper.AddConfigPath("/etc/headscale/")
viper.AddConfigPath("$HOME/.headscale")
viper.AddConfigPath(".")
func LoadConfig(path string, isFile bool) error {
if isFile {
viper.SetConfigFile(path)
} else {
// For testing
viper.AddConfigPath(path)
viper.SetConfigName("config")
if path == "" {
viper.AddConfigPath("/etc/headscale/")
viper.AddConfigPath("$HOME/.headscale")
viper.AddConfigPath(".")
} else {
// For testing
viper.AddConfigPath(path)
}
}
viper.SetEnvPrefix("headscale")