vultr / govultr

Vultr Go API client
MIT License
230 stars 56 forks source link

[BUG] - JSON error on empty user data for instances #231

Closed optik-aper closed 2 years ago

optik-aper commented 2 years ago

Describe the bug When using GetUserData on an instance that doesn't have the user data populated an error is thrown:

json: cannot unmarshal array into Go struct field UserData.user_data.data of type string
panic: json: cannot unmarshal array into Go struct field UserData.user_data.data of type string

To Reproduce

Additional context The response body from the API is in the form of

{
    "user_data": {
        "data": []
    }
}

But govultr is expecting a string, not an array.

optik-aper commented 2 years ago

This is the root cause of vultr/vultr-cli#281

optik-aper commented 2 years ago

When testing this, if user data is added, then the API returns it as a string. The API is not consistent in how it's returning data.

json: cannot unmarshal string into Go struct field UserData.user_data.data of type []string
panic: json: cannot unmarshal string into Go struct field UserData.user_data.data of type []string
optik-aper commented 2 years ago

This will need to be fixed in the API so that it's returning a consistent data structure, regardless of data state.

optik-aper commented 2 years ago

Issue resolved by an API update