Skip to content

Commit

Permalink
fix(rest): handle pointer value in the parameter (#432)
Browse files Browse the repository at this point in the history
Co-authored-by: iawia002 <[email protected]>
  • Loading branch information
caicloud-bot and iawia002 authored Jan 4, 2021
1 parent d9bc298 commit e68c9c7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,26 @@ type Request struct {
data interface{}
}

func toString(value interface{}) string {
ret := value
v := reflect.ValueOf(value)
if v.Kind() == reflect.Ptr {
ret = v.Elem()
}
return fmt.Sprint(ret)
}

// Path sets path parameter.
func (r *Request) Path(name string, value interface{}) *Request {
r.paths[name] = fmt.Sprint(value)
r.paths[name] = toString(value)
return r
}

// Query sets query parameter.
func (r *Request) Query(name string, values ...interface{}) *Request {
m := r.queries
for _, value := range values {
m[name] = append(m[name], fmt.Sprint(value))
m[name] = append(m[name], toString(value))
}
return r
}
Expand All @@ -213,7 +222,7 @@ func (r *Request) Query(name string, values ...interface{}) *Request {
func (r *Request) Header(name string, values ...interface{}) *Request {
m := r.headers
for _, value := range values {
m[name] = append(m[name], fmt.Sprint(value))
m[name] = append(m[name], toString(value))
}
return r
}
Expand All @@ -222,7 +231,7 @@ func (r *Request) Header(name string, values ...interface{}) *Request {
func (r *Request) Form(name string, values ...interface{}) *Request {
m := r.forms
for _, value := range values {
m[name] = append(m[name], fmt.Sprint(value))
m[name] = append(m[name], toString(value))
}
return r
}
Expand Down

0 comments on commit e68c9c7

Please sign in to comment.