• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

struct 질문

20.11.05 18:01 작성 조회수 89

0

안녕하세요 공부하다가 찾아보니 궁금해서 질문합니다.

type Bird struct {
	Species     string `json:"birdType"`
	Description string `json:"what it does"`
}

struct에 ``안에 있는내용을 어떤걸 뜻하는지 잘 모르겠습니다. 태깅하는건 알겠는데 json이 왜 붙어있는지 잘모르겠습니다.

답변 1

답변을 작성해보세요.

0

좋은 질문입니다.

grave 키가 golang struct에서 아래와 같은 기능을 합니다.

type NetworkInterface struct {

    Gateway              string `json:"gateway"`
    IPAddress            string `json:"ip"`
    IPPrefixLen          int    `json:"ip_prefix_len"`
    MacAddress           string `json:"mac"`
    ...
}

위를 예를들고 gateway 필드는
output 부분을 유심히 봐주세요~

n := NetworkInterface{
   Gateway : "foo"
}
json.Marshal(n)
// will output `{"gateway":"foo",...}`