Skip to content

Instantly share code, notes, and snippets.

@craicoverflow
Last active February 28, 2019 21:46
Show Gist options
  • Save craicoverflow/602027502a75e06c531c921fe79daf83 to your computer and use it in GitHub Desktop.
Save craicoverflow/602027502a75e06c531c921fe79daf83 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"github.com/craicoverflow/go-environment-variables-example/config"
"github.com/joho/godotenv"
)
// init is invoked before main()
func init() {
// loads values from .env into the system
if err := godotenv.Load(); err != nil {
log.Print("No .env file found")
}
}
func main() {
conf := config.New()
// Print out environment variables
fmt.Println(conf.GitHub.Username)
fmt.Println(conf.GitHub.APIKey)
fmt.Println(conf.DebugMode)
fmt.Println(conf.MaxUsers)
// Print out each role
for _, role := range conf.UserRoles {
fmt.Println(role)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment