mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-28 14:45:49 +08:00
Fix more lint warnings
This commit is contained in:
@ -57,7 +57,7 @@ func gitParse(c *Controller) (*git.Repo, error) {
|
||||
repo.Path = filepath.Clean(c.Root + string(filepath.Separator) + args[1])
|
||||
fallthrough
|
||||
case 1:
|
||||
repo.Url = args[0]
|
||||
repo.URL = args[0]
|
||||
}
|
||||
|
||||
for c.NextBlock() {
|
||||
@ -66,7 +66,7 @@ func gitParse(c *Controller) (*git.Repo, error) {
|
||||
if !c.NextArg() {
|
||||
return nil, c.ArgErr()
|
||||
}
|
||||
repo.Url = c.Val()
|
||||
repo.URL = c.Val()
|
||||
case "path":
|
||||
if !c.NextArg() {
|
||||
return nil, c.ArgErr()
|
||||
@ -103,19 +103,19 @@ func gitParse(c *Controller) (*git.Repo, error) {
|
||||
}
|
||||
|
||||
// if repo is not specified, return error
|
||||
if repo.Url == "" {
|
||||
if repo.URL == "" {
|
||||
return nil, c.ArgErr()
|
||||
}
|
||||
|
||||
// if private key is not specified, convert repository url to https
|
||||
// if private key is not specified, convert repository URL to https
|
||||
// to avoid ssh authentication
|
||||
// else validate git url
|
||||
// else validate git URL
|
||||
// Note: private key support not yet available on Windows
|
||||
var err error
|
||||
if repo.KeyPath == "" {
|
||||
repo.Url, repo.Host, err = sanitizeHttp(repo.Url)
|
||||
repo.URL, repo.Host, err = sanitizeHTTP(repo.URL)
|
||||
} else {
|
||||
repo.Url, repo.Host, err = sanitizeGit(repo.Url)
|
||||
repo.URL, repo.Host, err = sanitizeGit(repo.URL)
|
||||
// TODO add Windows support for private repos
|
||||
if runtime.GOOS == "windows" {
|
||||
return nil, fmt.Errorf("Private repository not yet supported on Windows")
|
||||
@ -134,12 +134,12 @@ func gitParse(c *Controller) (*git.Repo, error) {
|
||||
return repo, repo.Prepare()
|
||||
}
|
||||
|
||||
// sanitizeHttp cleans up repository url and converts to https format
|
||||
// sanitizeHTTP cleans up repository URL and converts to https format
|
||||
// if currently in ssh format.
|
||||
// Returns sanitized url, hostName (e.g. github.com, bitbucket.com)
|
||||
// and possible error
|
||||
func sanitizeHttp(repoUrl string) (string, string, error) {
|
||||
url, err := url.Parse(repoUrl)
|
||||
func sanitizeHTTP(repoURL string) (string, string, error) {
|
||||
url, err := url.Parse(repoURL)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@ -148,46 +148,46 @@ func sanitizeHttp(repoUrl string) (string, string, error) {
|
||||
url.Path = url.Path[len("git@"):]
|
||||
i := strings.Index(url.Path, ":")
|
||||
if i < 0 {
|
||||
return "", "", fmt.Errorf("Invalid git url %s", repoUrl)
|
||||
return "", "", fmt.Errorf("Invalid git url %s", repoURL)
|
||||
}
|
||||
url.Host = url.Path[:i]
|
||||
url.Path = "/" + url.Path[i+1:]
|
||||
}
|
||||
|
||||
repoUrl = "https://" + url.Host + url.Path
|
||||
repoURL = "https://" + url.Host + url.Path
|
||||
|
||||
// add .git suffix if missing
|
||||
if !strings.HasSuffix(repoUrl, ".git") {
|
||||
repoUrl += ".git"
|
||||
if !strings.HasSuffix(repoURL, ".git") {
|
||||
repoURL += ".git"
|
||||
}
|
||||
|
||||
return repoUrl, url.Host, nil
|
||||
return repoURL, url.Host, nil
|
||||
}
|
||||
|
||||
// sanitizeGit cleans up repository url and converts to ssh format for private
|
||||
// repositories if required.
|
||||
// Returns sanitized url, hostName (e.g. github.com, bitbucket.com)
|
||||
// and possible error
|
||||
func sanitizeGit(repoUrl string) (string, string, error) {
|
||||
repoUrl = strings.TrimSpace(repoUrl)
|
||||
func sanitizeGit(repoURL string) (string, string, error) {
|
||||
repoURL = strings.TrimSpace(repoURL)
|
||||
|
||||
// check if valid ssh format
|
||||
if !strings.HasPrefix(repoUrl, "git@") || strings.Index(repoUrl, ":") < len("git@a:") {
|
||||
if !strings.HasPrefix(repoURL, "git@") || strings.Index(repoURL, ":") < len("git@a:") {
|
||||
// check if valid http format and convert to ssh
|
||||
if url, err := url.Parse(repoUrl); err == nil && strings.HasPrefix(url.Scheme, "http") {
|
||||
repoUrl = fmt.Sprintf("git@%v:%v", url.Host, url.Path[1:])
|
||||
if url, err := url.Parse(repoURL); err == nil && strings.HasPrefix(url.Scheme, "http") {
|
||||
repoURL = fmt.Sprintf("git@%v:%v", url.Host, url.Path[1:])
|
||||
} else {
|
||||
return "", "", fmt.Errorf("Invalid git url %s", repoUrl)
|
||||
return "", "", fmt.Errorf("Invalid git url %s", repoURL)
|
||||
}
|
||||
}
|
||||
hostUrl := repoUrl[len("git@"):]
|
||||
i := strings.Index(hostUrl, ":")
|
||||
host := hostUrl[:i]
|
||||
hostURL := repoURL[len("git@"):]
|
||||
i := strings.Index(hostURL, ":")
|
||||
host := hostURL[:i]
|
||||
|
||||
// add .git suffix if missing
|
||||
if !strings.HasSuffix(repoUrl, ".git") {
|
||||
repoUrl += ".git"
|
||||
if !strings.HasSuffix(repoURL, ".git") {
|
||||
repoURL += ".git"
|
||||
}
|
||||
|
||||
return repoUrl, host, nil
|
||||
return repoURL, host, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user