From 0fcc54967bdf43a90cfea3d65111893b6ab81ed9 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 17 Jul 2016 03:47:48 +0200 Subject: uint16 --- query/query.go | 8 ++++++-- query/query_test.go | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/query/query.go b/query/query.go index 046c1de..3437ee5 100644 --- a/query/query.go +++ b/query/query.go @@ -24,8 +24,10 @@ func isZero(v reflect.Value) bool { switch v.Kind() { case reflect.String, reflect.Slice: return v.Len() == 0 - case reflect.Int: + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return v.Int() == 0 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return v.Uint() == 0 case reflect.Bool: return v.Bool() == false } @@ -55,8 +57,10 @@ func marshalQuery(v reflect.Value) (string, error) { } else { q.Add(name, "0") } - case reflect.Int: + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: q.Add(name, strconv.Itoa(int(f.Int()))) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + q.Add(name, strconv.Itoa(int(f.Uint()))) case reflect.String: q.Add(name, f.String()) case reflect.Slice, reflect.Array: diff --git a/query/query_test.go b/query/query_test.go index 5aaf61a..3a12630 100644 --- a/query/query_test.go +++ b/query/query_test.go @@ -9,17 +9,19 @@ func TestMarshal(t *testing.T) { C string `query:",optional"` D [3]byte E []byte + F uint16 }{ A: "test", B: 100, D: [3]byte{1, 2, 3}, E: []byte{'A', 'B'}, + F: 65535, } v, err := Marshal(q) if err != nil { t.Error(err) } - if v != "?b=100&d=%01%02%03&e=AB&x=test" { + if v != "?b=100&d=%01%02%03&e=AB&f=65535&x=test" { t.Error("wrong result", v) } -- cgit v1.2.3