Home >Backend Development >Golang >How to Unmarshal YAML into a Go struct with unexported fields?

How to Unmarshal YAML into a Go struct with unexported fields?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-08 03:47:08364browse

How to Unmarshal YAML into a Go struct with unexported fields?

Go Unmarshaling YAML into struct

The issue presented in the code is that the struct fields are not exported. To make them exported, use capital letters at the beginning of the field names like so:

type Config struct {</p>
<pre class="brush:php;toolbar:false">FooBar string `yaml:"foo_bar"`

}

The code will now successfully unmarshal the YAML data into the Config struct.

The above is the detailed content of How to Unmarshal YAML into a Go struct with unexported fields?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn