feat: init repo
This commit is contained in:
32
cfg/cfg.go
Normal file
32
cfg/cfg.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user