Last active
February 28, 2019 21:46
-
-
Save craicoverflow/602027502a75e06c531c921fe79daf83 to your computer and use it in GitHub Desktop.
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 ( | |
"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