Skip to content

Commit

Permalink
fixed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed Dec 10, 2019
1 parent f865720 commit db9c055
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ type Config struct {
}

func main() {
_ = os.Setenv("API_HOST", "127.0.0.1")
_ = os.Setenv("API_PORT", "8080")
_ = os.Setenv("API_PASSWORD", "test")
_ = os.Setenv("API_ES_HOST", "127.0.0.1")
_ = os.Setenv("API_ES_PORT", "8080")
_ = os.Setenv("API_ES_PASSWORD", "test")

var cfg Config
loader := env.New("API_", log.Printf)
Expand Down
21 changes: 21 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package env_test
import (
"fmt"
"github.com/qiangxue/go-env"
"log"
"os"
)

type Config struct {
Host string
Port int
Password string `env:",secret"`
}

func Example_one() {
Expand All @@ -25,3 +27,22 @@ func Example_one() {
// 127.0.0.1
// 8080
}

func Example_two() {
_ = os.Setenv("API_HOST", "127.0.0.1")
_ = os.Setenv("API_PORT", "8080")
_ = os.Setenv("API_PASSWORD", "test")

var cfg Config
loader := env.New("API_", log.Printf)
if err := loader.Load(&cfg); err != nil {
panic(err)
}
fmt.Println(cfg.Host)
fmt.Println(cfg.Port)
fmt.Println(cfg.Password)
// Output:
// 127.0.0.1
// 8080
// test
}

0 comments on commit db9c055

Please sign in to comment.