aboutsummaryrefslogtreecommitdiffstats
path: root/clients/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients/common.go')
-rw-r--r--clients/common.go42
1 files changed, 12 insertions, 30 deletions
diff --git a/clients/common.go b/clients/common.go
index 8d45a34..1eeacf0 100644
--- a/clients/common.go
+++ b/clients/common.go
@@ -13,52 +13,34 @@ package clients
import (
"fmt"
- "net/url"
"gopkg.in/src-d/go-git.v4/clients/common"
"gopkg.in/src-d/go-git.v4/clients/http"
"gopkg.in/src-d/go-git.v4/clients/ssh"
)
-// DefaultProtocols are the protocols supported by default.
-var DefaultProtocols = map[string]common.GitUploadPackService{
- "http": http.NewGitUploadPackService(),
- "https": http.NewGitUploadPackService(),
- "ssh": ssh.NewGitUploadPackService(),
-}
-
-// KnownProtocols holds the current set of known protocols. Initially
-// it gets its contents from `DefaultProtocols`. See `InstallProtocol`
-// below to add or modify this variable.
-var KnownProtocols = make(map[string]common.GitUploadPackService, len(DefaultProtocols))
+type GitUploadPackServiceFactory func(common.Endpoint) common.GitUploadPackService
-func init() {
- for k, v := range DefaultProtocols {
- InstallProtocol(k, v)
- }
+// Protocols are the protocols supported by default.
+var Protocols = map[string]GitUploadPackServiceFactory{
+ "http": http.NewGitUploadPackService,
+ "https": http.NewGitUploadPackService,
+ "ssh": ssh.NewGitUploadPackService,
}
// InstallProtocol adds or modifies an existing protocol.
-func InstallProtocol(scheme string, service common.GitUploadPackService) {
- if service == nil {
- panic("nil service")
- }
-
- KnownProtocols[scheme] = service
+func InstallProtocol(scheme string, f GitUploadPackServiceFactory) {
+ Protocols[scheme] = f
}
// NewGitUploadPackService returns the appropriate upload pack service
// among of the set of known protocols: HTTP, SSH. See `InstallProtocol`
// to add or modify protocols.
-func NewGitUploadPackService(repoURL string) (common.GitUploadPackService, error) {
- u, err := url.Parse(repoURL)
- if err != nil {
- return nil, fmt.Errorf("invalid url %q", repoURL)
- }
- s, ok := KnownProtocols[u.Scheme]
+func NewGitUploadPackService(endpoint common.Endpoint) (common.GitUploadPackService, error) {
+ f, ok := Protocols[endpoint.Scheme]
if !ok {
- return nil, fmt.Errorf("unsupported scheme %q", u.Scheme)
+ return nil, fmt.Errorf("unsupported scheme %q", endpoint.Scheme)
}
- return s, nil
+ return f(endpoint), nil
}