Giter Club home page Giter Club logo

Comments (5)

guiguan avatar guiguan commented on May 16, 2024 2

@inhere awesome, it works! Thanks for the prompt fix. 新年快乐!

from config.

inhere avatar inhere commented on May 16, 2024 1

released the https://github.com/gookit/config/releases/tag/v2.0.21

from config.

inhere avatar inhere commented on May 16, 2024

decode from json:

map[string]interface {} {
  "lang": map[string]interface {} {
    "allowed": map[string]interface {} {
      "en": string("ddd"),
    },
  },
},

map key is string type.


decode from yaml:

map[string]interface {} {
  "lang": map[interface {}]interface {} {
    "allowed": map[interface {}]interface {} {
      "en": string("666"),
    },
  },
},

map key is interface {} type.


so, panic on the merge.go line 119:

https://github.com/imdario/mergo/blob/cd55aeac72a19c6d5826061d5125d72b252a12eb/merge.go#L114-L121

from config.

inhere avatar inhere commented on May 16, 2024

hi @guiguan
I add the yamlv3 package for resolve you problem. see go-yaml/yaml#385 (comment)

usage:

import "github.com/gookit/config/v2/yamlv3"


config.AddDriver(yamlv3.Driver) 

tests please see:

config/issues_test.go

Lines 42 to 68 in dcf1e49

func TestIssues37_yaml_v3(t *testing.T) {
is := assert.New(t)
c := config.New("test")
c.AddDriver(yamlv3.Driver)
err := c.LoadStrings(config.JSON, `
{
"lang": {
"allowed": {
"en": "ddd"
}
}
}
`)
is.NoError(err)
dump.Println(c.Data())
err = c.LoadStrings(config.Yaml, `
lang:
newKey: hhh
allowed:
en: "666"
`)
is.NoError(err)
dump.Println(c.Data())
}

tests output:

=== RUN   TestIssues37_yaml_v3
PRINT AT github.com/gookit/config/v2_test.TestIssues37_yaml_v3(issues_test.go:58)
map[string]interface {} {
  "lang": map[string]interface {} {
    "allowed": map[string]interface {} {
      "en": string("ddd"),
    },
  },
},
PRINT AT github.com/gookit/config/v2_test.TestIssues37_yaml_v3(issues_test.go:67)
map[string]interface {} {
  "lang": map[string]interface {} {
    "allowed": map[string]interface {} {
      "en": string("666"),
    },
    "newKey": string("hhh"),
  },
},
--- PASS: TestIssues37_yaml_v3 (0.00s)
PASS

from config.

inhere avatar inhere commented on May 16, 2024

新年快乐!

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.