Move git and url checks into pkg
This moves the IsGIT and IsURL functions out of the generic `utils` package and into their own `urlutil` pkg. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
ecb536e190
commit
d7eadc78dc
3 changed files with 92 additions and 0 deletions
30
urlutil/git.go
Normal file
30
urlutil/git.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package urlutil
|
||||
|
||||
import "strings"
|
||||
|
||||
var (
|
||||
validPrefixes = []string{
|
||||
"git://",
|
||||
"github.com/",
|
||||
"git@",
|
||||
}
|
||||
)
|
||||
|
||||
// IsGitURL returns true if the provided str is a git repository URL.
|
||||
func IsGitURL(str string) bool {
|
||||
if IsURL(str) && strings.HasSuffix(str, ".git") {
|
||||
return true
|
||||
}
|
||||
for _, prefix := range validPrefixes {
|
||||
if strings.HasPrefix(str, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsGitTransport returns true if the provided str is a git transport by inspecting
|
||||
// the prefix of the string for known protocols used in git.
|
||||
func IsGitTransport(str string) bool {
|
||||
return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue