我想从 URL 中检索一个值。假设我有一个 URL,例如 http://myurl.com/theValue1/iWantToRetrieveThis
,我想拆分这个值并想检索 theValue1
和 iWantToRetrieveThis
。我该怎么做?
我试过下面的代码,但它似乎只是检索查询字符串:
func decodeGetTokenRequest(_ context.Context, r *http.Request) (request interface{}, err error) {
fmt.Println("decoding here", path.Base(r.URL))
return getTokenRequest{
SellerID: r.URL.Query().Get("sellerid"), <<--- THis is empty
Scope: r.URL.Query().Get("scope"), <<-- This is also empty
Authorization: Validation{
credential: r.Header.Get("ETM-API-AUTH-KEY"),
},
}, nil
}
最佳答案
好吧,我不得不接受@Rafal 的回答,因为我要检索的不是查询参数,而是 url 的一部分。
关于url - 从 URL 中提取值字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50964672/