I am writing an app using the Instagram API. I am receiving a JSON request and that gets Unmarshal
'ed into nested structs.
// the nested structs
type ResponseData struct {
ID string `json:"id"`
Link string `json:"link"`
Type string `json:"type"`
User struct {
FullName string `json:"full_name"`
ID int `json:"id"`
ProfilePicture string `json:"profile_picture"`
Username string `json:"username"`
}
Images struct {
Standard_Resolution struct {
URL string `json:"url"`
}
}
}
For the Image url to be added it needs to have the underscore in Standard_Resolution
, I am using Go Plus Package for Atom and I get the lint warning:
don't use underscores in Go names; struct field Standard_Resolution should be StandardResolution
Is there another way for me fix the error and still have the value in my struct.
Update:
I can add an identifier after the last brace for StandardResolution
.
StandardResolution struct {
URL string `json:"url"`
} `json:"standard_resolution"`
Anyway it is easier to read if you don't use nested structs.
type RDUser struct { ... }
type RDStandardResolution struct { ... }
type RDImages struct {
StandardResolition RDStandardResolution `json:"standard_resolution"`
}
type ResponseData struct {
...
User RDUser `json:"user"`
Images RDImages `json:"images"`
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.