Skip to content

ListMachines unmarshaling/decoding is broken #4

Description

@jgrowl
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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions