Last active
February 28, 2019 21:21
-
-
Save craicoverflow/deff89a1ba897c6a9a827578123913c3 to your computer and use it in GitHub Desktop.
Using the config struct in Go
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/joho/godotenv" | |
"github.com/craicoverflow/go-environment-variables-example/config" | |
) | |
// 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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment