// Personal website of Chris Smith

Go » Modify path of a URL

Using path.Join directly doesn’t work as it will break the scheme. Instead, parse the URL and only perform path operations on the path element.

u, err := url.Parse(target)
if err != nil {
	// ... 
}
u.Path = path.Join(path.Dir(u.Path), relativePath)
str := u.String()