Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListMachines unmarshaling/decoding is broken #4

Open
jgrowl opened this issue Jul 4, 2015 · 1 comment
Open

ListMachines unmarshaling/decoding is broken #4

jgrowl opened this issue Jul 4, 2015 · 1 comment

Comments

@jgrowl
Copy link

jgrowl commented Jul 4, 2015

caused by: failed unmarshaling/decoding the response body: [{"id":"xxx-xxx-xxx-xxx-xxx","name":"xxx_1","type":"smartmachine","state":"running","image":"xxx-xxx-xxx-xxx","ips":["192.168.128.25"],"memory":128,"disk":3072,"metadata":{},"tags":{"sdc_docker":true},"created":"2015-06-25T22:14:01.462Z","updated":"2015-06-25T22:14:14.000Z","dataset":"xxx-xxx-xxx-xxx-xxx","primaryIp":"","firewall_enabled":true,"compute_node":"xxx-xxx-xxx-xxx","package":"t4-standard-128M"}]
caused by: json: cannot unmarshal array into Go value of type cloudapi.Machine

If I comment out the following section in the joyent/gocommon/http/client it works as expected:

func decodeStream(d *json.Decoder, into interface{}) error {
    t := reflect.TypeOf(into)
    if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Slice {
        return fmt.Errorf("unexpected type %s", t)
    }
//  elemType := t.Elem().Elem()
//  slice := reflect.ValueOf(into).Elem()
//
//  for {
//      val := reflect.New(elemType)
//      if err := d.Decode(val.Interface()); err != nil {
////            fmt.Println(err)
//          if err == io.EOF {
//              break
//          }
//          return err
//      }
//      slice.Set(reflect.Append(slice, val.Elem()))
//  }
    return nil
}
@jgrowl
Copy link
Author

jgrowl commented Jul 4, 2015

This is how I am calling it (basically just as the tests do):

func sdcListen() {
    readPrivateKey("/home/xxx/Downloads/deploy_id_rsa")

    setup(&s)
    client := client.NewClient(s.creds.SdcEndpoint.URL, cloudapi.DefaultAPIVersion, s.creds, &cloudapi.Logger)
    s.testClient = cloudapi.New(client)

    filter := cloudapi.NewFilter()
    filter.Set("memory", "128")

    machines, err := s.testClient.ListMachines(filter)

    if err != nil {
        log.Fatal(err)
    }

    for _, m := range machines {
        log.Println(m.Id)
        log.Println(m.Created)
    }

}

func setup(s *LocalTests) {
    // Set up a Joyent CloudAPI service.
    authentication, err := auth.NewAuth("my-user-name", string(privateKey), "rsa-sha256")

    if err != nil {
        log.Fatal(err)
    }
    s.creds = &auth.Credentials{
        UserAuthentication: authentication,
        SdcKeyId:           "xxx",
        SdcEndpoint:        auth.Endpoint{URL: "https://us-east-1.api.joyentcloud.com"},
    }
}

type LocalTests struct {
    //LocalTests
    creds      *auth.Credentials
    testClient *cloudapi.Client
}

@jgrowl jgrowl changed the title ListMachines is broke ListMachines unmarshaling/decoding is broken Jul 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant