2017-06-05 10:52:14 +08:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
func JoinURI(elem ...string) string {
|
|
|
|
if len(elem) <= 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
uri := ""
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
for i, u := range elem {
|
|
|
|
u = strings.Replace(u, "\\", "/", -1)
|
2017-06-05 10:52:14 +08:00
|
|
|
|
|
|
|
if i == 0 {
|
2018-01-26 17:17:38 +08:00
|
|
|
if !strings.HasSuffix(u, "/") {
|
2017-06-05 10:52:14 +08:00
|
|
|
u = u + "/"
|
|
|
|
}
|
|
|
|
uri = u
|
2018-01-26 17:17:38 +08:00
|
|
|
} else {
|
|
|
|
u = strings.Replace(u, "//", "/", -1)
|
|
|
|
if strings.HasPrefix(u, "/") {
|
2017-06-05 10:52:14 +08:00
|
|
|
u = string(u[1:])
|
|
|
|
}
|
|
|
|
uri += u
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return uri
|
|
|
|
}
|