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
Release: 2024-12-08 03:47:08
Original
398 people have browsed it

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>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">FooBar string `yaml:"foo_bar"`
Copy after login

}

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template