Files
goreportcard/download/download.go
Nicolò Santamaria e6fde6c851 Remove vcs package since its behaviour diverges from cmd/go.
As stated in the issue https://github.com/golang/go/issues/11490
the package 'vcs' diverges significantly from cmd/go import path resolution
behaviour and thus needs to be removed for goreportcard to support
modules and versioning.
See also: https://golang.org/cl/159818.
2022-02-06 09:45:06 +09:00

35 lines
794 B
Go

package download
import (
"strings"
)
// Clean trims any URL parts, like the scheme or username, that might be present
// in a user-submitted URL
func Clean(path string) string {
return trimUsername(trimScheme(path))
}
// trimScheme removes a scheme (e.g. https://) from the URL for more
// convenient pasting from browsers.
func trimScheme(repo string) string {
schemeSep := "://"
schemeSepIdx := strings.Index(repo, schemeSep)
if schemeSepIdx > -1 {
return repo[schemeSepIdx+len(schemeSep):]
}
return repo
}
// trimUsername removes the username for a URL, if it is present
func trimUsername(repo string) string {
usernameSep := "@"
usernameSepIdx := strings.Index(repo, usernameSep)
if usernameSepIdx > -1 {
return repo[usernameSepIdx+len(usernameSep):]
}
return repo
}