Skip to content

Commit

Permalink
added real world example program
Browse files Browse the repository at this point in the history
  • Loading branch information
Mat Ryer committed Jun 27, 2014
1 parent 264b8cb commit 0b02fef
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

example/example
41 changes: 41 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

/*
In Terminal:
# build the file
go build -o example
# set the environment variable
TEST_STRING=Hello
# run the code
./example
# run the code with a different variable for
# this particular execution of the program
TEST_STRING=Goodbye ./example
*/

import (
"log"

"github.com/joeshaw/envdecode"
)

type config struct {
TestString string `env:"TEST_STRING"`
}

func main() {

var cfg config
if err := envdecode.Decode(&cfg); err != nil {
log.Fatalf("Failed to decode: %s", err)
}

log.Println("TEST_STRING:", cfg.TestString)

}

0 comments on commit 0b02fef

Please sign in to comment.