github.com/lmars/docker@v1.6.0-rc2/pkg/urlutil/git.go (about)

     1  package urlutil
     2  
     3  import "strings"
     4  
     5  var (
     6  	validPrefixes = []string{
     7  		"git://",
     8  		"github.com/",
     9  		"git@",
    10  	}
    11  )
    12  
    13  // IsGitURL returns true if the provided str is a git repository URL.
    14  func IsGitURL(str string) bool {
    15  	if IsURL(str) && strings.HasSuffix(str, ".git") {
    16  		return true
    17  	}
    18  	for _, prefix := range validPrefixes {
    19  		if strings.HasPrefix(str, prefix) {
    20  			return true
    21  		}
    22  	}
    23  	return false
    24  }
    25  
    26  // IsGitTransport returns true if the provided str is a git transport by inspecting
    27  // the prefix of the string for known protocols used in git.
    28  func IsGitTransport(str string) bool {
    29  	return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
    30  }