romana / core

Romana core components - Micro services written in Go.
Apache License 2.0
47 stars 11 forks source link

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

Open flashvoid opened 8 years ago

flashvoid commented 8 years ago

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.

debedb commented 8 years ago

This I think has been fixed, and findOne/findAll functionality from https://github.com/paninetworks/core/pull/9 obsoletes this problem.