Go YAML 파일 Unmarshal

Jmnote (토론 | 기여)님의 2023년 1월 19일 (목) 13:13 판 (새 문서: ==개요== ;Go YAML 파일 Unmarshal <syntaxhighlight lang='yaml' multi=1 file='a.yaml'> id: 1 name: Reds colors: - Crimson - Red - Ruby - Maroon </syntaxhighlight> <syntaxhighlight...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

Go YAML 파일 Unmarshal
id: 1
name: Reds
colors:
- Crimson
- Red
- Ruby
- Maroon
package main

import (
        "fmt"
        "gopkg.in/yaml.v2"
        "io/ioutil"
)

type ColorGroup struct {
        ID     int
        Name   string
        Colors []string
}

func main() {
        yamlFile, err := ioutil.ReadFile("a.yaml")
        if err != nil {
                fmt.Println("ReadFile error:", err)
                return
        }
        var cg ColorGroup
        err = yaml.Unmarshal(yamlFile, &cg)
        if err != nil {
                fmt.Println("Unmarshal error:", err)
                return
        }
        fmt.Printf("%+v", cg)
}

2 같이 보기

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