v0.0.382 add build url method
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
This commit is contained in:
29
langext/url.go
Normal file
29
langext/url.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user