Merge pull request #302 from vladimyr/url-clone

Clone URLs by copying `net.URL` struct
This commit is contained in:
Masayuki Matsuki 2020-10-31 10:46:38 +09:00 committed by GitHub
commit a6f2792d94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 16 deletions

View file

@ -17,13 +17,7 @@ type metaImport struct {
}
func detectGoImport(u *url.URL) (string, *url.URL, error) {
goGetU := &url.URL{ // clone
Scheme: u.Scheme,
User: u.User,
Host: u.Host,
Path: u.Path,
RawQuery: u.RawQuery,
}
goGetU := *u
q := goGetU.Query()
q.Add("go-get", "1")
goGetU.RawQuery = q.Encode()

View file

@ -43,21 +43,14 @@ func (repo *GitHubRepository) IsValid() bool {
// VCS returns VCSBackend of the repository
func (repo *GitHubRepository) VCS() (*VCSBackend, *url.URL, error) {
origU := repo.URL()
u := &url.URL{ // clone
Scheme: origU.Scheme,
User: origU.User,
Host: origU.Host,
Path: origU.Path,
RawQuery: origU.RawQuery,
}
u := *repo.url
pathComponents := strings.Split(strings.Trim(strings.TrimSuffix(u.Path, ".git"), "/"), "/")
path := "/" + strings.Join(pathComponents[0:2], "/")
if strings.HasSuffix(u.String(), ".git") {
path += ".git"
}
u.Path = path
return GitBackend, u, nil
return GitBackend, &u, nil
}
// A GitHubGistRepository represents a GitHub Gist repository.