Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested lookup failing #154

Open
urso opened this issue Feb 22, 2020 · 0 comments
Open

Nested lookup failing #154

urso opened this issue Feb 22, 2020 · 0 comments
Labels

Comments

@urso
Copy link

urso commented Feb 22, 2020

go-ucfg supports lookup based on the result string value. Lookup fails when the final expansion is an object, but still works if the target is a primitive value.

Test program:

package main

import (
	"encoding/json"
	"fmt"
	"log"
	"os"

	"github.com/elastic/beats/libbeat/common"
)

func main() {
	files := os.Args[1:]
	cfg, err := common.LoadFiles(files...)
	if err != nil {
		log.Fatal(err)
	}

	tmp := map[string]interface{}{}
	if err := cfg.Unpack(&tmp); err != nil {
		log.Fatal(err)
	}

	b, err := json.MarshalIndent(tmp, "", "    ")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s\n", b)
}

First test file (a.yml):

setting: ${${select}}
select: test
test: a

Second test file (b.yml):

setting: ${${select}}
select: test
test:
  key: value

Expected output:

$ go run main.go a.yml
{
    "select": "test",
    "setting": "a",
    "test": "a"
}
$ go run main.go b.yml
{
    "select": {
        "key": "value",
    },
    "setting": "a",
    "test": {
        "key": "value"
     }
}

Actual output:

go run main.go a.yml
{
    "select": "test",
    "setting": "a",
    "test": "a"
}
$ go run main.go b.yml
2020/02/22 09:46:45 type mismatch accessing 'setting' (source:'b.yml')
exit status 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants