Skip to content

Instantly share code, notes, and snippets.

@madflojo
Last active May 16, 2021 21:49
Show Gist options
  • Save madflojo/d5e3b95ba830b820e1bf1689c043258b to your computer and use it in GitHub Desktop.
Save madflojo/d5e3b95ba830b820e1bf1689c043258b to your computer and use it in GitHub Desktop.
Viper Article - Viper replacing Config
package app
import (
// imports go here
"github.com/spf13/viper"
)
// Common errors returned by this app.
var (
ErrShutdown = fmt.Errorf("application shutdown gracefully")
)
// cfg is used across the app package to contain configuration.
var cfg *viper.Viper
// Run starts the primary application. It handles starting background services,
// populating package globals & structures, and clean up tasks.
func Run(c *viper.Viper) error {
// Apply config provided by main
cfg = c
// Application logic goes here
}
// Stop is used to gracefully shutdown the server.
func Stop() {
// Stop logic goes here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment