go-wifi-switcher/cfg/cfg.go

34 lines
767 B
Go

package cfg
import (
"log"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
type Config struct {
Page string `required:"true" split_words:"true"`
AdminUser string `required:"true" split_words:"true"`
Password string `required:"true" split_words:"true"`
LogFile bool `required:"true" split_words:"true"`
Bin string `required:"true" split_words:"true"`
}
func NewConfig(envFilePath string) *Config {
if envFilePath != "" {
err := godotenv.Load(envFilePath)
if err != nil {
log.Fatalf("environment variable ENV is empty and an error occurred while loading the .env file\n")
}
}
cfg := &Config{}
err := envconfig.Process("", cfg)
if err != nil {
log.Fatalf("envconfig.Process: %s\n", err)
}
return cfg
}