Golang nested structures, unmarshaling with underscores

I am writing an application using the Instagram API. I receive a JSON request and get Unmarshal'ed in nested structures.

// 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"`
        }
    }
}

In order for the image URL to be added, it must have an underscore in Standard_Resolution, I use the Go Plus Atom Package and I will get a warning:

Do not use underscores in Go names. struct field Standard_Resolution must be StandardResolution

Is there any other way for me to fix the error and still make a difference in my structure.

Update:

I can add an identifier after the last bracket for StandardResolution.

StandardResolution struct {
    URL string `json:"url"`
} `json:"standard_resolution"`
+4
source share
1 answer

, , .

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"`
}
+1

All Articles