Skip to content

restClient.Get always expects single value but always receives a list #90

@flashvoid

Description

@flashvoid

Relevant to https://github.com/romana/core/blob/fix/k8s-listener

Example in https://github.com/romana/core/blob/fix/k8s-listener/romana/kubernetes/listener.go#L286

    t := &tenant.Tenant{}
    err = l.restClient.Get(fmt.Sprintf("%s/tenants/%s", tenantURL, ns), t)

produces

2016/05/16 04:17:43 translateNetworkPolicy(): For namespace tenant-a got &tenant.Tenant{ID:0x0, ExternalID:"", Name:"", Segments:[]tenant.Segment(nil), Seq:0x0} / &errors.errorString{s:"Error json: cannot unmarshal array into Go value of type tenant.Tenant (<nil>) when parsing [{\"ID\":2,\"ExternalID\":\"680214b74eb14cd58a30a1c251aa2af6\",\"Name\":\"tenant-a\",\"Segments\":null,\"Seq\":2}]"}
2016/05/16 04:17:43 Error json: cannot unmarshal array into Go value of type tenant.Tenant (<nil>) when parsing [{"ID":2,"ExternalID":"680214b74eb14cd58a30a1c251aa2af6","Name":"tenant-a","Segments":null,"Seq":2}]

I couldn't find an easy way to fix it, changing tenant.go to return a single result doesn't help - clients always receive a list of httpResponses even if there is only one item.

Passing a slice of []Tenant{} into restClient.Get always returns empty slice because slice can't be modified by reference.

Need help.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions