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) + +}