本文整理匯總了Golang中github.com/openshift/source-to-image/pkg/scm/git.Git.ValidCloneSpec方法的典型用法代碼示例。如果您正苦於以下問題:Golang Git.ValidCloneSpec方法的具體用法?Golang Git.ValidCloneSpec怎麽用?Golang Git.ValidCloneSpec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/source-to-image/pkg/scm/git.Git
的用法示例。
在下文中一共展示了Git.ValidCloneSpec方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: checkSourceURI
// checkSourceURI performs a check on the URI associated with the build
// to make sure that it is valid. It also optionally tests the connection
// to the source uri.
func checkSourceURI(git git.Git, rawurl string, testConnection bool, timeout time.Duration) error {
if !git.ValidCloneSpec(rawurl) {
return fmt.Errorf("Invalid git source url: %s", rawurl)
}
if strings.HasPrefix(rawurl, "[email protected]") || strings.HasPrefix(rawurl, "git://") {
return nil
}
srcURL, err := url.Parse(rawurl)
if err != nil {
return err
}
if !testConnection {
return nil
}
host := srcURL.Host
if strings.Index(host, ":") == -1 {
switch srcURL.Scheme {
case "http":
host += ":80"
case "https":
host += ":443"
}
}
dialer := net.Dialer{Timeout: timeout}
conn, err := dialer.Dial("tcp", host)
if err != nil {
return err
}
return conn.Close()
}
示例2: checkSourceURI
// checkSourceURI performs a check on the URI associated with the build
// to make sure that it is valid. It also optionally tests the connection
// to the source uri.
func checkSourceURI(git git.Git, rawurl string, timeout time.Duration) error {
if !git.ValidCloneSpec(rawurl) {
return fmt.Errorf("Invalid git source url: %s", rawurl)
}
return checkRemoteGit(rawurl, timeout)
}