Skip to content

Commit

Permalink
update doc and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiling-J committed Nov 21, 2021
1 parent b4191a6 commit b62c499
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
![Go Report Card](https://goreportcard.com/badge/github.com/yiling-j/piper?style=flat-square)

- **Single Source of Truth**
- **Code Generation, No Typo**
- **Generated Key Structs, No Typo**
- **Config Inheritance**
- **Multiple Config Strategies Support**
- **Cache For Better Performance**

## Why Piper
If you are familiar with Django, this is how Django settings module looks like:
Expand Down Expand Up @@ -125,9 +126,12 @@ import (
var configFS embed.FS

os.Setenv("SECRET", "qux")
piper.Load("config/stage.toml")
// make sure turn on AutomaticEnv first then loading config,
// this way the env vaiable is also cached, so IGet* methods can work properly
piper.V().AutomaticEnv()
piper.Load("config/stage.toml")
secret := piper.GetString(config.Secret)

```

### Strategy III - Copy config directory
Expand Down
14 changes: 13 additions & 1 deletion integration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestMultiPiper(t *testing.T) {

}

func TestEnvOverride(t *testing.T) {
func TestEnvOverrideI(t *testing.T) {
piper.Reset()
err := piper.Load("config_toml_multi/test.toml")
require.Nil(t, err)
Expand All @@ -164,6 +164,18 @@ func TestEnvOverride(t *testing.T) {
require.Equal(t, piper.IGetString(configtm.Foo), "test")
}

func TestEnvOverrideII(t *testing.T) {
piper.Reset()
piper.V().AutomaticEnv()
err := os.Setenv("FOO", "bar")
require.Nil(t, err)
err = piper.Load("config_toml_multi/test.toml")
require.Nil(t, err)

require.Equal(t, piper.GetString(configtm.Foo), "bar")
require.Equal(t, piper.IGetString(configtm.Foo), "bar")
}

func BenchmarkGet(b *testing.B) {
piper.Reset()
err := piper.Load("config_yaml_multi/test.yaml")
Expand Down

0 comments on commit b62c499

Please sign in to comment.