我想从URL中检索一个值。如果我有一个像http://myurl.com/theValue1/iWantToRetrieveThis
的URL,我想分割这个值,并想要检索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回答,因为我正在尝试检索的不是查询参数,而是网址的一部分。