6

I have following url:

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

I wonder how I can obtain last path segment (bar) from myUrl.Path?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
pixel
  • 24,905
  • 36
  • 149
  • 251

1 Answers1

10

Use path.Base to get the last element of a path: path.Base(myUrl.Path)

Run it on the playground.

Charlie Tumahai
  • 113,709
  • 12
  • 249
  • 242