aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/dashapi
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-07-25 20:25:53 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-07-25 20:25:53 +0200
commit841aeb030309aac1be7008191e4c0a396cc17ce9 (patch)
tree45add4c5e41dd495e896d88486162bbbd68ad281 /dashboard/dashapi
parent4f5ad2aa53df28fe52510da499d8149dfe611baf (diff)
dashboard/dashapi: always zero reply
json decoding behavior is somewhat surprising (see // https://github.com/golang/go/issues/21092). This behavior is especially easy to hit in tests that reuse reply objects. To avoid any surprises, we zero the reply.
Diffstat (limited to 'dashboard/dashapi')
-rw-r--r--dashboard/dashapi/dashapi.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/dashboard/dashapi/dashapi.go b/dashboard/dashapi/dashapi.go
index 79b0368b1..8f5856fd9 100644
--- a/dashboard/dashapi/dashapi.go
+++ b/dashboard/dashapi/dashapi.go
@@ -14,6 +14,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
+ "reflect"
"strings"
)
@@ -157,6 +158,16 @@ type (
)
func Query(client, addr, key, method string, ctor RequestCtor, doer RequestDoer, req, reply interface{}) error {
+ if reply != nil {
+ // json decoding behavior is somewhat surprising
+ // (see // https://github.com/golang/go/issues/21092).
+ // To avoid any surprises, we zero the reply.
+ typ := reflect.TypeOf(reply)
+ if typ.Kind() != reflect.Ptr {
+ return fmt.Errorf("resp must be a pointer")
+ }
+ reflect.ValueOf(reply).Elem().Set(reflect.New(typ.Elem()).Elem())
+ }
values := make(url.Values)
values.Add("client", client)
values.Add("key", key)