Comments (4)
The internal merge is based on applying yaml unmarshaler repeatedly on the same variable, which doesn't have any documented merge behavior and is not recursive for interface{}, but is for structs. Here is an example:
package main
import (
"fmt"
yaml "gopkg.in/yaml.v2"
)
const (
base = `
test:
testmap:
testkey: test
`
dev = `
test:
testmap:
testkey2: anothervalue
`
)
func main() {
type Config struct {
Test map[string]interface{} `yaml:"test"`
}
type StructConfig struct {
Test struct {
Testmap struct {
Testkey string
Testkey2 string
}
}
}
var c Config
var s StructConfig
for _, str := range []string{base, dev} {
if err := yaml.Unmarshal([]byte(str), &c); err != nil {
panic(err)
}
if err := yaml.Unmarshal([]byte(str), &s); err != nil {
panic(err)
}
}
fmt.Printf("interface config:\n %+v\n", c)
fmt.Printf("struct config:\n %+v\n", s)
}
Output:
interface config:
{Test:map[testmap:map[testkey2:anothervalue]]}
struct config:
{Test:{Testmap:{Testkey:test Testkey2:anothervalue}}}
Config library is being consistent in that case and behaves in a similar way as json merge patch by merging everything recursively.
from config.
I was under the impression that the internal configuration library was always
performing a deep merge--that seems like the correct behavior to have if we're
going to have merging at all.
@alsamylkin, putting aside whether we should do this or not, is it even
technically feasible to replicate the behavior?
from config.
@abhinav Unfortunately it doesn't do a deep merge and I don't see we can replicate this behavior: merge and decoding are separate steps in config library, but the internal merge depends on the type of variable being decoded. I am happy to jam offline on a solution though.
from config.
Synced offline and decided to not to try mimic the internal merge and keep it as is.
from config.
Related Issues (20)
- Improve merge error messages
- Env var expansion logic inconsistent HOT 1
- Breaking change for NewProviderGroup in 1.3.0? HOT 2
- 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
- Better error messages for missing config vars
- 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.