func main() {
beego.Router("/", &MainController{})
beego.Router("/userid/", &SqlController{})
beego.Run()
}
this works fine for url "http://localhost:8080/userid" but if i want user id value to be dynamic for ex "http://localhost:8080?userid=1" i could not how o achieve this using router in go.
Extracting xxx
from ?id=xxx
is about request parameter parsing, you can get examples in beego's document.
Routing (in your context) is about mapping requests matching a certain pattern to corresponding actions. When id is different, I suppose what you want is not getting them mapped to different actions. So it shouldn't be called routing. It's just parameter parsing.
Not sure about beego, but using go http request you can access the query parameters like this request.URL.Query()
, where request
is of type *http.Request
. What you want is basically query parameters from the URL? So you get the URL object from the the request and then access the query parameters. The Query()
method returns a map[string][]string