Skip to content

Commit

Permalink
Add GetArrayUniquif
Browse files Browse the repository at this point in the history
  • Loading branch information
verzth committed Mar 9, 2020
1 parent 403b458 commit f17e979
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func SomeHandler(w http.ResponseWriter, r *http.Request) {
birthdate, err := req.GetTime("birthdate") // Get birthdate value as *time.Time with Error handler
birthdate := req.GetTimeNE("birthdate") // Get birthdate value as *time.Time with No Error
ids := req.GetArray("ids") // Get ids value as Array of interface{}
ids := req.GetArrayUniquify("ids") // Get ids value as Array of interface{} and uniquify if possible
obj := req.GetMap("object") // Get object value as Map of map[string]interface{}
obj := req.GetStruct("object") // Get object value as struct of interface{}
json := req.GetJSON("jsonstring") // Get jsonstring value as jumper.JSON
Expand Down
6 changes: 4 additions & 2 deletions demo/Demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ func index(w http.ResponseWriter, r *http.Request) {
var req = jumper.PlugRequest(r, w)
var res = jumper.PlugResponse(w)

vn := req.GetMap("list")["obj"]
fmt.Println(vn.(map[string]interface{})["id"].([]interface{})[0])
/*vn := req.GetMap("list")["obj"]
fmt.Println(vn.(map[string]interface{})["id"].([]interface{})[0])*/

fmt.Println(req.Get("test"))

res.ReplySuccess("0000000", "SSSSSS", "Success", nil)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.13
require (
github.com/gorilla/handlers v1.4.2 // indirect
github.com/gorilla/mux v1.7.3
github.com/verzth/go-utils v0.0.1
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YAR
github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/verzth/go-utils v0.0.0-20200309094323-2bdeb06102e3 h1:77yI9b2G1/95WInYP6fUl6fFIlVtSEpjexJquXRKLTU=
github.com/verzth/go-utils v0.0.0-20200309094323-2bdeb06102e3/go.mod h1:VRAnwae+xXZT8FwlbZFKmgUB5U/DzHAfuREIxitR/FA=
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=
11 changes: 11 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/gorilla/mux"
"github.com/verzth/go-utils/utils"
"mime/multipart"
"net/http"
"strconv"
Expand Down Expand Up @@ -374,6 +375,16 @@ func (r *Request) GetArray(key string) []interface{} {
return nil
}

func (r *Request) GetArrayUniquify(key string) []interface{} {
if r.params[key] != nil {
if v, ok := r.params[key].([]interface{}); ok {
utils.Uniquify(&v)
return v
}
}
return nil
}

func (r *Request) GetMap(key string) map[string]interface{} {
if r.params[key] != nil {
if v, ok := r.params[key].(map[string]interface{}); ok {
Expand Down

0 comments on commit f17e979

Please sign in to comment.