cannot unmarshal !!seq into string in Go

Solution 1:

As mkopriva, said in the comments, you should change to []string, so the struct would be

type ENV struct {
    Attributes []string `yaml:"attributes"`
}

And why is that ? the yaml, reconizes the ENV: attributes: - foo - boo - coo as a array. What you can do to turn into one string, is use: strings.Join(String Slice,{ something to separate, you can let this as "")`

the imports are : "strings", and strings.Join returns a string.

Solution 2:

As per suggestion of mkopriva changing Attributes field to string[] instead of string:

package test

import (
    "fmt"
    "gopkg.in/yaml.v3"
    "io/ioutil"
    "log"
    "testing"
)

type ENV struct {
    Attributes []string `yaml:"attributes"`
}

func TestTerraformAzureCosmosDBExample(t *testing.T) {

    yFile, err := ioutil.ReadFile("config.yaml")

    if err != nil {
        log.Fatal(err)
    }

    data := make(map[string]ENV)

    err = yaml.Unmarshal(yFile, &data)
    if err != nil {
        log.Fatal(err)
    }
    for k, v := range data {
        fmt.Printf(`key: %v, value: %v`, k, v)
    }

}