starting on frontend, auth finished for backend
This commit is contained in:
20
config.go
20
config.go
@@ -11,17 +11,25 @@ import (
|
||||
type Config struct {
|
||||
Timezone string `fig:"tz" default:"America/New_York"`
|
||||
Server struct {
|
||||
Port string `fig:"port" default:"3000"`
|
||||
Port string `fig:"port" default:"3000"`
|
||||
LocationPhotoDir string `fig:"locationPhotoDir" default:"./app/photos/locations/"`
|
||||
}
|
||||
Logger struct {
|
||||
Level string `fig:"loglevel" default:"info"`
|
||||
LoggingFile string `fig:"loggingFile" default:"./app/log/goInventorize.log"`
|
||||
}
|
||||
Authentication struct {
|
||||
BasicAuth bool `fig:"basicauth"`
|
||||
UserName string `fig:"username" default:"admin"`
|
||||
Password string `fig:"password" default:"password"`
|
||||
}
|
||||
|
||||
Development bool `fig:"development"` // Cannot set default for BOOL will default to false if nothing supplied
|
||||
}
|
||||
|
||||
func LoadConfig(s *Server) error {
|
||||
var cfg Config
|
||||
err := fig.Load(&cfg, fig.File("config.yaml"), fig.Dirs("./app/config"), fig.UseEnv("")) // Load in config.yaml, then overwrite with ENV variables
|
||||
err := fig.Load(&cfg, fig.File("config.yaml"), fig.Dirs("./app/config"), fig.UseEnv("GI")) // Load in config.yaml, then overwrite with ENV variables prefixed with GI
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -49,10 +57,14 @@ func LoadConfig(s *Server) error {
|
||||
return time.Now().In(loc)
|
||||
}
|
||||
s.Log = zerolog.New(logFile).With().Timestamp().Logger()
|
||||
// Creating photo directory
|
||||
err = os.MkdirAll(cfg.Server.LocationPhotoDir, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer logFile.Close()
|
||||
s.Log.Info().Msg("Configuration loaded successfully...")
|
||||
s.Log.Debug().Msgf("Values: Server Port: %s Logging File: %s Logging Level: %s Timezone: %s", cfg.Server.Port, cfg.Logger.LoggingFile, cfg.Logger.Level, cfg.Timezone)
|
||||
s.Log.Debug().Msgf("%+v", cfg)
|
||||
s.Config = &cfg
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user