Skip to content

Instantly share code, notes, and snippets.

@KScaesar
Last active September 23, 2018 11:21
Show Gist options
  • Select an option

  • Save KScaesar/f13fb52f6a54fc773462780c508b9ad7 to your computer and use it in GitHub Desktop.

Select an option

Save KScaesar/f13fb52f6a54fc773462780c508b9ad7 to your computer and use it in GitHub Desktop.
//問題1用到的struct
type IssuesSearchResult struct {
TotalCount int `json:"total_count"`
//為什麼使用 struct pointer 作內嵌欄位
//不能直接定義為
//Items []Issue ?
Items []*Issue
}
//問題1用到的struct
type Issue struct {
Number int
HTMLURL string `json:"html_url"`
Title string
State string
User *User
CreatedAt time.Time `json:"created_at"`
Body string
}
//問題1用到的struct
type User struct {
Login string
HTMLURL string `json:"html_url"`
}
//問題3
//自己重新定義struct,將上述所有struct定義在一個struct之中
//效率會比較好嗎? 缺點是? 可讀性差?
type MyTestStruct struct {
TotalCount int `json:"total_count"`
Items []struct {
Number int
HTMLURL string `json:"html_url"`
Title string
State string
User struct {
Login string
HTMLURL string `json:"html_url"`
}
CreatedAt time.Time `json:"created_at"`
Body string
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment