Tag Yaml

custom yaml marshaling in go

In Go, you need to have field tags in your structs to instruct YAML machinery to properly marshal and unmarshal, i.e. convert from and to YAML bytes. type User struct { Name string `yaml:"name"` Surname string `yaml:"surname"` } This requirement cannot always be easily achievable when you don’t control all the implementation of the types of the fields. Go playground link. package main import ( "log" "net/url" "gopkg.in/yaml.v3" ) func main() { type User struct { Name string `yaml:"name"` Surname string `yaml:"surname"` Website *url.