goext/langext/url.go
Timo Vetter 1c7dc1820a
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
v0.0.382 add build url method
2024-02-09 12:25:01 +01:00

30 lines
512 B
Go

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
}