【问题标题】:How to obtain the last path segment of a URL如何获取 URL 的最后一个路径段
【发布时间】:2020-04-13 18:04:29
【问题描述】:

我有以下网址:

targetUrl := "http://google.com/foo/bar?a=1&b=2"
myUrl, err := url.Parse(targetUrl)

我想知道如何从myUrl.Path 获取最后一个路径段(bar)?

【问题讨论】:

    标签: go path uri segment


    【解决方案1】:

    使用path.Base 获取路径的最后一个元素:path.Base(myUrl.Path)

    Run it on the playground.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-30
      • 2011-05-02
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      相关资源
      最近更新 更多