package main
import (
"fmt"
"gopkg.in/yaml.v3"
)
type ColorGroup struct {
ID int
Name string
Colors []string
}
func main() {
colorGroup := ColorGroup{
ID: 1,
Name: "Reds",
Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
}
yamlBytes, err := yaml.Marshal(colorGroup)
if err != nil {
fmt.Println("error:", err)
}
fmt.Println(string(yamlBytes))
}
package main
import (
"fmt"
"gopkg.in/yaml.v3"
)
type Animal struct {
Name string
Order string
}
func main() {
animals := []Animal{
{
Name: "Platypus",
Order: "Monotremata",
},
{
Name: "Quoll",
Order: "Dasyuromorphia",
},
}
yamlBytes, err := yaml.Marshal(animals)
if err != nil {
fmt.Println("error:", err)
}
fmt.Println(string(yamlBytes))
}