Skip to content

Instantly share code, notes, and snippets.

@sanan-fataliyev
Created July 8, 2020 17:46
Show Gist options
  • Select an option

  • Save sanan-fataliyev/11f599e996d86d1743fc7bb8272369e5 to your computer and use it in GitHub Desktop.

Select an option

Save sanan-fataliyev/11f599e996d86d1743fc7bb8272369e5 to your computer and use it in GitHub Desktop.
// JoinURLs joins base URL and paths safely
// No worries for extra or missing slashes
func JoinURLs(baseURL string, paths ...string) string {
if len(paths) == 0 {
return baseURL
}
joint := strings.TrimRight(baseURL, "/")
for _, path := range paths {
joint += "/" + strings.TrimLeft(path, "/")
}
return joint
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment