Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
beckend committed May 24, 2021
1 parent e5297d1 commit e593034
Showing 1 changed file with 2 additions and 41 deletions.
43 changes: 2 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,6 @@ go get -u github.com/beckend/go-config

---

### option LoadConfigs allows loading from custom sources

See test for details, the gist is

```golang
var result TestValidateStructOne
_, err := config.New(&config.NewOptions{
ConfigUnmarshal: &result,
EnvKeyRunEnv: "RUN_ENV",
LoadConfigs: func(options *config.LoadConfigsOptions) ([][]byte, error) {
b1, err := options.TOML.BytesToJSON([]byte("RunEnv = 'overriden'"))
if err != nil {
return nil, err
}

b2, err := options.TOML.StringToJSON("AccessKey = 'overriden'")
if err != nil {
return nil, err
}

b3, err := options.TOML.ReaderToJSON(strings.NewReader("Shell = 'overriden'"))
if err != nil {
return nil, err
}

return [][]byte{b1, b2, b3}, nil
},
PathConfigs: path.Join(pathFixtures, "configs-base"),
})
if err != nil {
panic(err)
}

Expect(result.RunEnV).To(Equal("overriden"))
Expect(result.AccessKey).To(Equal("overriden"))
Expect(result.Shell).To(Equal("overriden"))
Expect(result.Password).To(Equal("defaultpassword"))
```

### Description and usage

- a directory with config files
Expand Down Expand Up @@ -111,7 +72,7 @@ func main() {

---

### option LoadConfigs allows loading from custom sources
### option `LoadConfigs` allows loading from custom sources

Returning an array of json marshalled bytes, the order matter where the later one will override the previous.
See `main_test.go` for details, the gist is
Expand Down Expand Up @@ -169,7 +130,7 @@ Expect(result.Password).To(Equal("defaultpassword"))

---

### option OnConfigBeforeValidation allows modifications before struct is going to be validated to do custom logic before validation
### option `OnConfigBeforeValidation` allows modifications before struct is going to be validated to do custom logic before validation

Good place to add complex logic to read/replace variables, at this stage all env variables have been replaced

Expand Down

0 comments on commit e593034

Please sign in to comment.