Comments (2)
Any suggestions on what I'm doing wrong/how to adjust?
from config.
@tormoder Apologies for a long turn-around. This seems to have slipped under the cracks.
It's not entirely clear what you are trying to do since you're doing overrides in the same file. I can only assume that you have some sort of a base configuration object and you introduce new flavors as you go along. If that is the case, you can use YAML itself, rather than relying on the config library.
The Go yaml parser supports anchors as far as I can tell (although I've never used it in any meaningful capacity).
Here is an example.
Config file that has an object with base values and a,b that inherit and override values.
❯ cat config.yaml
base: &base
foo: bar
herp: derp
a:
<<: *base
foo: baz
b:
<<: *base
herp: NOPE
❯ cat main.go
package main
import (
"fmt"
"go.uber.org/config"
)
func main() {
type obj struct {
Foo string `yaml:"foo"`
Herp string `yaml:"herp"`
}
var conf struct {
A obj `yaml:"a"`
B obj `yaml:"b"`
}
provider, err := config.NewYAMLProviderFromFiles("config.yaml")
if err != nil {
panic(err)
}
if err := provider.Get(config.Root).Populate(&conf); err != nil {
panic(err)
}
fmt.Println("A >>", conf.A)
fmt.Println("B >>", conf.B)
}
As you can see running it produces the correct A,B structs that contain the override values, and the inheritance from default.
❯ go run main.go
A >> {baz derp}
B >> {bar NOPE}
Perhaps that is what you are looking for?
from config.
Related Issues (20)
- Improve merge error messages
- Env var expansion logic inconsistent HOT 1
- Support non-string scalar keys in mappings.
- Ensure replacement values are properly quoted when necessary HOT 5
- Error loading env variables over some size HOT 2
- Update dependencies HOT 1
- Dependencies security
- Report merge error during provider group construction HOT 1
- Add support for handling config structs' dependency (tag "yaml inline") HOT 3
- android arm build overflow HOT 1
- Check for formatting and lint errors in CI HOT 2
- What is the design target for this project? HOT 1
- YAML unmarshal seems to ignore null HOT 1
- NopProvider returns true for `HasValue()` HOT 2
- Populating strings with values that could be parsed as booleans mutates the result HOT 5
- Cannot populate fields with omitempty tag HOT 1
- Populate does not return a copy of the value, allowing callers to modify the config HOT 1
- Environment variable expansion also applies to comments HOT 1
- `yaml:"service.name"` couldn't be parsed correctly after 46dea54a68b3e94c239093186902985c7ced97b5 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from config.