diff options
author | Alberto Cortés <alberto@sourced.tech> | 2015-12-16 19:41:29 +0100 |
---|---|---|
committer | Alberto Cortés <alberto@sourced.tech> | 2015-12-16 19:41:29 +0100 |
commit | bf98b6096fd1e813ebadbb1f71d4b2d4e48bdb4b (patch) | |
tree | 662e91b988a5bf79fe9c6d1a02a2df91d4596d27 /clients/common.go | |
parent | 990573b9bf06d12fdafbe09664e47736a48746d8 (diff) | |
download | go-git-bf98b6096fd1e813ebadbb1f71d4b2d4e48bdb4b.tar.gz |
Add client selection based on repo URL scheme
Diffstat (limited to 'clients/common.go')
-rw-r--r-- | clients/common.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/clients/common.go b/clients/common.go index fcbacf5..b2e906d 100644 --- a/clients/common.go +++ b/clients/common.go @@ -1,10 +1,31 @@ package clients import ( + "fmt" + "net/url" + "gopkg.in/src-d/go-git.v2/clients/common" + "gopkg.in/src-d/go-git.v2/clients/file" "gopkg.in/src-d/go-git.v2/clients/http" + "gopkg.in/src-d/go-git.v2/clients/ssh" ) -func NewGitUploadPackService() common.GitUploadPackService { - return http.NewGitUploadPackService() +// NewGitUploadPackService returns the appropiate upload pack service +// among of the set of supported protocols: HTTP, SSH or file. +// TODO: should this get a scheme as an argument instead of an URL? +func NewGitUploadPackService(repoURL string) (common.GitUploadPackService, error) { + u, err := url.Parse(repoURL) + if err != nil { + return nil, fmt.Errorf("invalid url %q", repoURL) + } + switch u.Scheme { + case "http", "https": + return http.NewGitUploadPackService(), nil + case "ssh": + return ssh.NewGitUploadPackService(), nil + case "file": + return file.NewGitUploadPackService(), nil + default: + return nil, fmt.Errorf("unsupported scheme %q", u.Scheme) + } } |