使用Golang的Google App Engine:如何将URL路径段解析为变量?

Dou*_*sek 1 google-app-engine url-routing go

在Google App Engine with Go中,我想采用这样的网址:

http://www.example.com/api/account/123456/product/573832
Run Code Online (Sandbox Code Playgroud)

并像这样对待它:

http://www.example.com/api/account/{acctId}/product/{prodId}
Run Code Online (Sandbox Code Playgroud)

然后访问acctIdprodId在我的处理函数中.

我该怎么做呢?

Law*_*Mok 6

你在这:

func httpHandle(httpResponse http.ResponseWriter, httpRequest *http.Request) {
    urlPart := strings.Split(httpRequest.URL.Path, "/")
    // urlPart[3] is the acctId, urlPart[5] is the prodId
}
Run Code Online (Sandbox Code Playgroud)