从URL中提取值字符串

问题描述 投票:-2回答:1

我想从URL中检索一个值。如果我有一个像http://myurl.com/theValue1/iWantToRetrieveThis的URL,我想分割这个值,并想要检索theValue1iWantToRetrieveThis。我怎样才能做到这一点?

我尝试了下面的代码,但它似乎只检索查询字符串:

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
}
url go
1个回答
0
投票

好吧,我只需要使用@Rafal回答,因为我正在尝试检索的不是查询参数,而是网址的一部分。

© www.soinside.com 2019 - 2024. All rights reserved.