Created
May 11, 2022 13:49
-
-
Save madflojo/33412c123a2e6bbdb84559a7e232b5bc to your computer and use it in GitHub Desktop.
Go Project Structure - main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
// Initiate a simple logger | |
log := logrus.New() | |
// Setup Config | |
cfg := viper.New() | |
// Set Default Configs | |
cfg.SetDefault("enable_tls", true) | |
cfg.SetDefault("listen_addr", "0.0.0.0:8443") | |
cfg.SetDefault("cert_file", "/certs/cert.crt") | |
cfg.SetDefault("key_file", "/certs/key.key") | |
// Load Config | |
cfg.AddConfigPath("./conf") | |
cfg.SetEnvPrefix("app") | |
cfg.AllowEmptyEnv(true) | |
cfg.AutomaticEnv() | |
err := cfg.ReadInConfig() | |
if err != nil { | |
switch err.(type) { | |
case viper.ConfigFileNotFoundError: | |
log.Warnf("No Config file found, loaded config from Environment - Default path ./conf") | |
default: | |
log.Fatalf("Error when Fetching Configuration - %s", err) | |
} | |
} | |
// Run application | |
err = app.Run(cfg) | |
if err != nil && err != app.ErrShutdown { | |
log.Fatalf("Service stopped - %s", err) | |
} | |
log.Infof("Service shutdown - %s", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment