targetURL := "http://www.example.com/one/two/three.json?output=four" u, err := url.Parse(targetURL) if err != nil { panic(err) } fmt.Println(path.Base(u.Path)) // three.json