aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-07-17 03:47:48 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-07-17 03:47:48 +0200
commit0fcc54967bdf43a90cfea3d65111893b6ab81ed9 (patch)
treeccded813a9596d7de6d48dbeda5f72e16a6622e6
parent67f2a34819285b4712f46b3de66384c49cf01ef7 (diff)
uint16
-rw-r--r--query/query.go8
-rw-r--r--query/query_test.go4
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)
}