Giter VIP home page Giter VIP logo

Comments (4)

 avatar commented on July 23, 2024

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.

abhinav avatar abhinav commented on July 23, 2024

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.

 avatar commented on July 23, 2024

@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.

 avatar commented on July 23, 2024

Synced offline and decided to not to try mimic the internal merge and keep it as is.

from config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.