gpt4 book ai didi

google-app-engine - 带有 Golang : How do you parse URL path segments as variables? 的 Google App Engine

转载 作者:IT王子 更新时间:2023-10-29 01:53:09 25 4
gpt4 key购买 nike

在带有 Go 的 Google App Engine 中,我想采用这样的 URL:

http://www.example.com/api/account/123456/product/573832

并这样对待它:

http://www.example.com/api/account/{acctId}/product/{prodId}

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

我该怎么做?

最佳答案

给你:

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

关于google-app-engine - 带有 Golang : How do you parse URL path segments as variables? 的 Google App Engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26291336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com