Skip to content

Commit

Permalink
add validity check in params detector
Browse files Browse the repository at this point in the history
  • Loading branch information
verzth committed Mar 20, 2020
1 parent 60d113f commit b56c598
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.13
require (
github.com/gorilla/handlers v1.4.2
github.com/gorilla/mux v1.7.4
github.com/verzth/go-utils v0.1.0
github.com/verzth/go-utils v0.1.1
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ github.com/verzth/go-utils v0.0.1 h1:2ntXZMxhjUyegqEglNPUctbpc5NoRfF+AgNs2Q4ULN0
github.com/verzth/go-utils v0.0.1/go.mod h1:VRAnwae+xXZT8FwlbZFKmgUB5U/DzHAfuREIxitR/FA=
github.com/verzth/go-utils v0.1.0 h1:PheN6mb1kyAB/x4eSWUFUETZ6QrqTlUSQ0mueMZe2pQ=
github.com/verzth/go-utils v0.1.0/go.mod h1:VRAnwae+xXZT8FwlbZFKmgUB5U/DzHAfuREIxitR/FA=
github.com/verzth/go-utils v0.1.1 h1:IZeqWr5IP/bgVYIHZXrCQe3rx9/WUJaRrDnF5vlOOtA=
github.com/verzth/go-utils v0.1.1/go.mod h1:VRAnwae+xXZT8FwlbZFKmgUB5U/DzHAfuREIxitR/FA=
12 changes: 8 additions & 4 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (r *Request) GetAll() map[string] interface{} {

func (r *Request) Get(key string) string {
val := reflect.ValueOf(r.params[key])
if r.params[key] != nil || (val.Kind() == reflect.Slice && val.Len() > 0){
if r.params[key] != nil || (val.IsValid() && val.Kind() == reflect.Slice && val.Len() > 0){
return fmt.Sprintf("%v", r.params[key])
}
return ""
Expand Down Expand Up @@ -465,9 +465,13 @@ func (r *Request) Filled(keys... string) (found bool) {
for _, key := range keys {
found = found && r.has(key)
val := reflect.ValueOf(r.params[key])
switch val.Kind() {
case reflect.String: found = found && strings.TrimSpace(r.Get(key)) != ""
case reflect.Slice: found = found && val.Len() > 0
if val.IsValid() {
switch val.Kind() {
case reflect.String: found = found && strings.TrimSpace(r.Get(key)) != ""
case reflect.Slice: found = found && val.Len() > 0
}
}else{
found = false
}
}
return
Expand Down

0 comments on commit b56c598

Please sign in to comment.