aboutsummaryrefslogtreecommitdiffstats
path: root/clients/common.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-02-11 12:09:02 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-02-11 12:09:02 +0100
commitd0155564148550167e756e440b5f9ce71c76abb3 (patch)
treecb6f7637286c8236997dc736133bbac4217d5e35 /clients/common.go
parent35ee4d749be21691b78a7465361ad47179fe2eff (diff)
downloadgo-git-d0155564148550167e756e440b5f9ce71c76abb3.tar.gz
clients: removing url from the clients constructor
Diffstat (limited to 'clients/common.go')
-rw-r--r--clients/common.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/clients/common.go b/clients/common.go
index ce36dd1..24b3d63 100644
--- a/clients/common.go
+++ b/clients/common.go
@@ -28,16 +28,16 @@ type ServiceFromURLFunc func(url string) common.GitUploadPackService
// Wrapping is needed because you can not cast a function that
// returns an implementation of an interface to a function that
// returns the interface.
-var DefaultProtocols = map[string]ServiceFromURLFunc{
- "http": func(s string) common.GitUploadPackService { return http.NewGitUploadPackService(s) },
- "https": func(s string) common.GitUploadPackService { return http.NewGitUploadPackService(s) },
- "ssh": func(s string) common.GitUploadPackService { return ssh.NewGitUploadPackService(s) },
+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]ServiceFromURLFunc, len(DefaultProtocols))
+var KnownProtocols = make(map[string]common.GitUploadPackService, len(DefaultProtocols))
func init() {
for k, v := range DefaultProtocols {
@@ -53,17 +53,19 @@ func NewGitUploadPackService(repoURL string) (common.GitUploadPackService, error
if err != nil {
return nil, fmt.Errorf("invalid url %q", repoURL)
}
- srvFn, ok := KnownProtocols[u.Scheme]
+ service, ok := KnownProtocols[u.Scheme]
if !ok {
return nil, fmt.Errorf("unsupported scheme %q", u.Scheme)
}
- return srvFn(repoURL), nil
+
+ return service, nil
}
// InstallProtocol adds or modifies an existing protocol.
-func InstallProtocol(scheme string, serviceFn ServiceFromURLFunc) {
- if serviceFn == nil {
+func InstallProtocol(scheme string, service common.GitUploadPackService) {
+ if service == nil {
panic("nil service")
}
- KnownProtocols[scheme] = serviceFn
+
+ KnownProtocols[scheme] = service
}