Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/vendor/github.com/anacrolix/missinggo/url.go
akuma06 a41f938cec Add Godep support (#758)
As we have seen, dependencies version can prevent the build. We should
user lock versions on dependencies that we know work:
* Packages are vendored
* Add Godep support
* Added addtional install step in readme
* Fix travis build error
2017-05-26 13:07:22 +02:00

42 lignes
796 o
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()
}