Files
cloudpods/vendor/github.com/anacrolix/missinggo/url.go
Qiu Jian 2e587bd6ab glance重构 update 1
Conflicts:
	Gopkg.lock
	pkg/appsrv/appsrv.go
	pkg/cloudcommon/options.go
	pkg/compute/models/hosts.go
	pkg/compute/models/quotas.go
	pkg/compute/service/service.go
	pkg/mcclient/mcclient.go
2018-12-26 22:52:13 +08:00

43 lines
796 B
Go

package missinggo
import (
"net/url"
"path"
)
// Returns URL opaque as an unrooted path.
func URLOpaquePath(u *url.URL) string {
if u.Opaque != "" {
return u.Opaque
}
return u.Path
}
// Cleans the (absolute) URL path, removing unnecessary . and .. elements. See
// "net/http".cleanPath.
func CleanURLPath(p string) string {
if p == "" {
return "/"
}
if p[0] != '/' {
p = "/" + p
}
cp := path.Clean(p)
// Add the trailing slash back, as it's relevant to a URL.
if p[len(p)-1] == '/' && cp != "/" {
cp += "/"
}
return cp
}
func URLJoinSubPath(base, rel string) string {
baseURL, err := url.Parse(base)
if err != nil {
// Honey badger doesn't give a fuck.
panic(err)
}
rel = CleanURLPath(rel)
baseURL.Path = path.Join(baseURL.Path, rel)
return baseURL.String()
}