Go YAML Marshal omitempty

1 개요[ | ]

Go YAML Marshal omitempty
package main

import (
	"fmt"

	"gopkg.in/yaml.v3"
)

type Fruit struct {
	Name  string `yaml:"name"`
	Price int    `yaml:"price,omitempty"`
}

func main() {
	fruits := []Fruit{
		{Name: "apple", Price: 1},
		{Name: "banana", Price: 0},
		{Name: "melon", Price: 0},
	}
	yamlBytes, _ := yaml.Marshal(fruits)
	fmt.Println(string(yamlBytes))
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}