Go Unmarshaling YAML into struct

前端 未结 2 1313
南旧
南旧 2020-12-21 08:37

I am trying to parse a YAML data into a string:

package main

import (
    \"fmt\"
    \"log\"
    \"gopkg.in/yaml.v2\"
)

type Config struct {
    foo_bar s         


        
相关标签:
2条回答
  • 2020-12-21 09:14

    The capital matters:

    foo_bar --> Foo_bar

    0 讨论(0)
  • 2020-12-21 09:23

    Your struct's fields are unexported. Export them and it'll work.

    type Config struct {
        FooBar string `yaml:"foo_bar"`
    }
    
    0 讨论(0)
提交回复
热议问题