Commit 6c32e071 authored by kargakis's avatar kargakis

Dont output nil; test nil & omitempty

parent edfaa480
...@@ -74,7 +74,13 @@ func addParam(values url.Values, tag string, omitempty bool, value reflect.Value ...@@ -74,7 +74,13 @@ func addParam(values url.Values, tag string, omitempty bool, value reflect.Value
if omitempty && zeroValue(value) { if omitempty && zeroValue(value) {
return return
} }
values.Add(tag, fmt.Sprintf("%v", value.Interface())) val := ""
iValue := fmt.Sprintf("%v", value.Interface())
if iValue != "<nil>" {
val = iValue
}
values.Add(tag, val)
} }
func addListOfParams(values url.Values, tag string, omitempty bool, list reflect.Value) { func addListOfParams(values url.Values, tag string, omitempty bool, list reflect.Value) {
......
...@@ -151,6 +151,12 @@ func TestConvert(t *testing.T) { ...@@ -151,6 +151,12 @@ func TestConvert(t *testing.T) {
}, },
expected: url.Values{"ptr": {"<nil>"}, "bptr": {"true"}}, expected: url.Values{"ptr": {"<nil>"}, "bptr": {"true"}},
}, },
{
input: &baz{
Ptr: intp(5),
},
expected: url.Values{"ptr": {"5"}},
},
} }
for _, test := range tests { for _, test := range tests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment