Created
May 15, 2021 18:40
-
-
Save madflojo/f2da5917506bee1eb3e7421439e28e1e to your computer and use it in GitHub Desktop.
Viper Article - Main with Viper
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
package main | |
import ( | |
"github.com/madflojo/go-quick/app" | |
"github.com/sirupsen/logrus" | |
"github.com/spf13/viper" | |
) | |
func main() { | |
// Initiate a simple logger | |
log := logrus.New() | |
// Setup Config | |
cfg := viper.New() | |
// Load Config | |
cfg.SetEnvPrefix("app") | |
cfg.AllowEmptyEnv(true) | |
cfg.AutomaticEnv() | |
err := cfg.ReadInConfig() | |
if err != nil { | |
log.Warnf("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