JoinPath returns a new URL with the provided path elements joined to any existing path and the resulting path cleaned of any ./ or ../ elements. Any sequences of multiple / characters will be reduced to a single /. Path elements must already be in escaped form, as produced by PathEscape.
{
u, err := url.Parse("https://example.com/foo/bar")
if err != nil {
log.Fatal(err)
}
fmt.Println(u.JoinPath("baz", "qux"))
}Output:
https://example.com/foo/bar/baz/qux