From 08e08d771ef03df80248c80d81475fe7c5ea6fe7 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Wed, 23 Nov 2016 15:30:34 +0100 Subject: transport: create Client interface (#132) * plumbing: move plumbing/client package to plumbing/transport. * transport: create Client interface. * A Client can instantiate any client transport service. * InstallProtocol installs a Client for a given protocol, instead of just a UploadPackService. * A Client can open a session for fetch-pack or send-pack for a specific Endpoint. * Adapt ssh and http clients to the new client interface. * updated doc --- plumbing/transport/client/client.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 plumbing/transport/client/client.go (limited to 'plumbing/transport/client/client.go') diff --git a/plumbing/transport/client/client.go b/plumbing/transport/client/client.go new file mode 100644 index 0000000..5c6da05 --- /dev/null +++ b/plumbing/transport/client/client.go @@ -0,0 +1,32 @@ +package client + +import ( + "fmt" + + "gopkg.in/src-d/go-git.v4/plumbing/transport" + "gopkg.in/src-d/go-git.v4/plumbing/transport/http" + "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh" +) + +// Protocols are the protocols supported by default. +var Protocols = map[string]transport.Client{ + "http": http.DefaultClient, + "https": http.DefaultClient, + "ssh": ssh.DefaultClient, +} + +// InstallProtocol adds or modifies an existing protocol. +func InstallProtocol(scheme string, c transport.Client) { + Protocols[scheme] = c +} + +// NewClient returns the appropriate client among of the set of known protocols: +// HTTP, SSH. See `InstallProtocol` to add or modify protocols. +func NewClient(endpoint transport.Endpoint) (transport.Client, error) { + f, ok := Protocols[endpoint.Scheme] + if !ok { + return nil, fmt.Errorf("unsupported scheme %q", endpoint.Scheme) + } + + return f, nil +} -- cgit