UpCloudLtd / upcloud-go-api

Go client for UpCloud's API
https://pkg.go.dev/github.com/UpCloudLtd/upcloud-go-api/v6
MIT License
42 stars 9 forks source link

Enabling remote access breaks struct serialization #63

Closed ajmyyra closed 4 years ago

ajmyyra commented 4 years ago

Hi there,

I noticed that enabling remote access in the API (VNC console in the control panel) seems to completely break JSON serialization for server details, and instead of an error, only an empty struct is returned. Following example works well when remote access is disabled, but enabling it causes the JSON serialization to fail.

package main

import (
    "fmt"

    "github.com/UpCloudLtd/upcloud-go-api/upcloud/client"
    "github.com/UpCloudLtd/upcloud-go-api/upcloud/request"
    "github.com/UpCloudLtd/upcloud-go-api/upcloud/service"
)

func main() {
    api := service.New(client.New("username", "password")
    server, err := api.GetServerDetails(&request.GetServerDetailsRequest{UUID: "server_uuid"})
    if err != nil {
        fmt.Println(err)
    }
    fmt.Printf("%+v\n", server)
}

I looked at the relevant code and error from json.Unmarshal is left unhandled. Thus, no error is returned to the code utilizing GetServerDetails when serialization fails.

Besides this problem, the upgraded API bindings seem amazing and it's been working perfectly for me. Thank you!

PopoSensei commented 4 years ago

Added error handling in this commit. Also the underlying type error is being fixed in the main API.