Skip to content

Commit

Permalink
Merge pull request #5 from ahmdrz/master
Browse files Browse the repository at this point in the history
Fix nil value condition in structToURLValues function
  • Loading branch information
bgsrb authored May 28, 2018
2 parents 487fb64 + c0ef0b7 commit 3076b71
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions utils.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package kavenegar

import (
"fmt"
"encoding/json"
"fmt"
"net/url"
"reflect"
"strconv"
"strings"
"time"
)

//ToString ...
func ToString(i interface{}) string {
return strings.Trim(strings.Replace(fmt.Sprint(i), " ", ",", -1), "[]")
}

//ToJson ...
func ToJson(i interface{}) string {
_json,_ := json.Marshal(i)
_json, _ := json.Marshal(i)
return string(_json)
}

Expand All @@ -28,9 +29,9 @@ func ToUnix(t time.Time) string {
//structToUrlValues ...
func structToURLValues(i interface{}) url.Values {
v := url.Values{}
// if i == nil {
// return v
// }
if reflect.ValueOf(i).IsNil() {
return v
}
m := structToMapString(i)
for k, s := range m {
switch {
Expand Down Expand Up @@ -87,4 +88,4 @@ func valueToString(f reflect.Value) []string {
}

return v
}
}

0 comments on commit 3076b71

Please sign in to comment.