Yaml cannot parse parameters with more than one syllable

Hi,

I do not know if this is a bug or some kind of feature:

I have a yaml file with parameters whose names have multiple syllables:

...
worker_count: 4
...

Then I have this struct:

type AMQPConsumer struct {
    WorkerCount     int `yaml:"worker_count"`
    ...
}

Then the unmarshalling

import "gopkg.in/yaml.v2"

var c config.Config
b, _ := ioutil.ReadFile("config.yml")
yaml.Unmarshal(b, &c)

The result of c.WorkerCount is 0. But it works with one syllable. Anyone an idea? Maybe this is known and I just did not find it…

Parameters with multiple values works for me. Running

package main

import (
	"log"

	yaml "gopkg.in/yaml.v2"
)

type Config struct {
	WorkerCount int `yaml:"worker_count"`
}

func main() {
	log.SetFlags(log.Lshortfile)

	b := []byte("worker_count: 4")
	var c Config

	err := yaml.Unmarshal(b, &c)
	if err != nil {
		log.Fatalln(err)
	}

	log.Println(c.WorkerCount)
}

produces:

main.go:24: 4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.