在带有Go的Google App Engine中,我想采用以下网址:
http://www.example.com/api/account/123456/product/573832
并像这样对待它:
http://www.example.com/api/account/{acctId}/product/{prodId}
然后在我的处理程序函数中访问
acctId
和prodId
。我该怎么做呢?
最佳答案
你在这:
func httpHandle(httpResponse http.ResponseWriter, httpRequest *http.Request) {
urlPart := strings.Split(httpRequest.URL.Path, "/")
// urlPart[3] is the acctId, urlPart[5] is the prodId
}