diff --git a/README.md b/README.md index 72e4765..9c50b21 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/demo/Demo.go b/demo/Demo.go index a404d6b..0bdc15f 100644 --- a/demo/Demo.go +++ b/demo/Demo.go @@ -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) } \ No newline at end of file diff --git a/go.mod b/go.mod index f5ab809..3629006 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 84521ed..ccab149 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/request.go b/request.go index 81f6100..30dd15c 100644 --- a/request.go +++ b/request.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "github.com/gorilla/mux" + "github.com/verzth/go-utils/utils" "mime/multipart" "net/http" "strconv" @@ -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 {