From 0b02fef710ce2f8068147f2eef963a2d360641b4 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Fri, 27 Jun 2014 14:14:59 -0600 Subject: [PATCH] added real world example program --- .gitignore | 2 ++ example/main.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .gitignore create mode 100644 example/main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1faf59e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +example/example diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..0cd7b43 --- /dev/null +++ b/example/main.go @@ -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) + +}