Skip to content

Instantly share code, notes, and snippets.

@madflojo
Created May 15, 2021 18:40
Show Gist options
  • Save madflojo/f2da5917506bee1eb3e7421439e28e1e to your computer and use it in GitHub Desktop.
Save madflojo/f2da5917506bee1eb3e7421439e28e1e to your computer and use it in GitHub Desktop.
Viper Article - Main with Viper
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