Вход Yaml:
params:
- aws.region: ["us-west-1","us-west-2"]
- aws.s3path: ["s3-path-1", "s3-path-2"]
Код:
package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
func main() {
var f File
wfyaml, _ := os.Open("temp.yaml")
byteValue, _ := ioutil.ReadAll(wfyaml)
yaml.Unmarshal(byteValue, &f)
fmt.Print(f)
}
type File struct {
Params Params `yaml:"params"`
}
type Params []struct { // <<< This [] behavior is confusing
AwsRegion []string `yaml:"aws.region"`
S3path []string `yaml:"aws.s3path"`
}
Выход:
{[{[us-west-1 us-west-2] []} {[] [s3-path-1 s3-path-2]}]}%
Если я использую
type Params struct { // <<< This [] behavior is confusing
AwsRegion []string `yaml:"aws.region"`
S3path []string `yaml:"aws.s3path"`
}
Тогда вывод {{[] []}}%
Я не уверен, что я что-то здесь упускаю.