Created
July 8, 2020 17:46
-
-
Save sanan-fataliyev/11f599e996d86d1743fc7bb8272369e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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