Go YAML Marshal omitempty

Jmnote (토론 | 기여)님의 2023년 4월 5일 (수) 04:52 판 (새 문서: ==개요== ;Go YAML Marshal omitempty <syntaxhighlight lang='go' run> package main import ( "fmt" "gopkg.in/yaml.v3" ) type Fruit struct { Name string `yaml:"name"` Price int...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

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 }}