【发布时间】:2016-01-22 10:37:55
【问题描述】:
我在 Go 中设置了一个 GorrilaMux,如果在浏览器中输入特定的 URL,它将进行 API 调用。如果 URL 作为命令行参数给出,我想在我的 main 方法中进行相同的 API 调用。然而,似乎能够做到这一点的 http.redirect() 方法需要一个 HTTP ResponseWriter 和一个 *HTTPRequest 变量作为函数参数。我不知道如何在 main 方法中生成这些变量。我该怎么做,或者,有没有更好的方法从 Golang 中的 URL 进行 API 调用?
设置路由器的代码
func main(){
router := mux.NewRouter().StrictSlash(true)
for _, route := range routes { //Sets up predefined routes
router.
Path(route.Path).
Name(route.Name).
Handler(route.HandlerFunc)
}
URL:="localhost:8080/whatever" //URL I want to redirect, route would be "/whatever"
http.redirect(????)
}
【问题讨论】:
标签: go http-redirect