-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can i get an array value of context URLParam method? #701
Comments
At present, i am using: |
You could just get the slice of string (or As you know Iris is fully compatible with ctx.Request() // returns the *http.Request
ctx.ResponseWriter() // returns the http.ResponseWriter We can get the url values by, simply, using |
However if you want to fill a struct from query arguments, that is possible with the current implementation: // file: main.go
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
type Visitor struct {
Username string
Mail string
Data []string
// if you use uncomment this you have to use &mydata=data...
// Data []string `form:"mydata"`
}
func main() {
app := iris.New()
app.Get("/query", func(ctx context.Context) {
visitor := Visitor{}
err := ctx.ReadForm(&visitor)
if err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.WriteString(err.Error())
}
ctx.Writef("Visitor: %#v", visitor)
})
app.Run(iris.Addr(":8080"))
} go run main.go Open: http://localhost:8080/query?Username=myusername&Mail=mymail&Data=mydataaaa Result: Visitor: main.Visitor{Username:"myusername", Mail:"mymail", Data:[]string{"mydataaaa"}} Hope that answer your question :) |
How to get array like this? How to type struct? |
Read More info at:
} |
https://github.com/kataras/iris/blob/master/_examples/http_request/read-form/main.go#L11 A type PostDataForm struct {
RouterId int `json:"router_id" form:"router_id"`
RoleList []int `json:"role_list" form:"role_list"`
} Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-form/main.go |
Example: URI: /path?user[name]=Vinhjaxt&user[gender]=0
Can i get user array?
Any way like:
user:=ctx.URLParamGetArray("user").(map[string]interface{}); fmt.Println(user["name"].(string))
?Thank you!
The text was updated successfully, but these errors were encountered: