goext/langext/url.go

30 lines
512 B
Go
Raw Permalink Normal View History

2024-02-09 12:25:01 +01:00
package langext
import (
"fmt"
"strings"
)
func BuildUrl(url, path string, params *map[string]string) string {
if path[:1] == "/" && url[len(url)-1:] == "/" {
url += path[1:]
} else if path[:1] != "/" && url[len(url)-1:] != "/" {
url += "/" + path
} else {
url += path
}
if params == nil {
return url
}
for key, value := range *params {
if strings.Contains(url, "?") {
url += fmt.Sprintf("&%s=%s", key, value)
} else {
url += fmt.Sprintf("?%s=%s", key, value)
}
}
return url
}