I'm trying to parse JSON to a []struct, the JSON is retrieved from https://api.github.com/events However when I try to access each struct within the array I get an error:
type GITHUB_EVENT does not support indexing
How am I able to access each struct within the array?
func httpGetEvents() {
eventDataRAW := httpPageGet("https://api.github.com/events", true)
eventDataJSON := new(GITHUB_EVENT)
_ = json.Unmarshal([]byte(eventDataRAW), &eventDataJSON)
fmt.Println(eventDataJSON[0].Id)
}
//--------------------------------------------------------------------------------------//
type GITHUB_EVENT []struct {
Id string `json:"id"`
Type string `json:"type"`
Actor struct {
Id int `json:"id"`
Login string `json:"login"`
GravatarId string `json:"gravatar_id"`
Url string `json:"url"`
AvatarUrl string `json:"avatar_url"`
} `json:"actor"`
Repo struct {
Id int `json:"id"`
Name string `json:"name"`
Url string `json:"url"`
} `json:"repo"`
Payload struct {
PushId int `json:"push_id"`
Size int `json:"size"`
DistinctSize int `json:"distinct_size"`
Ref string `json:"ref"`
Head string `json:"head"`
Before string `json:"before"`
Commits []struct {
Sha string `json:"sha"`
Author struct {
Email string `json:"email"`
Name string `json:"name"`
} `json:"author"`
Message string `json:"message"`
Distinct bool `json:"distinct"`
Url string `json:"url"`
} `json:"commits"`
} `json:"payload"`
Public bool `json:"public"`
CreatedAt string `json:"created_at"`
}