Git Product home page Git Product logo

Comments (2)

tormoder avatar tormoder commented on August 28, 2024

Any suggestions on what I'm doing wrong/how to adjust?

from config.

glibsm avatar glibsm commented on August 28, 2024

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

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.