diff options
author | Santiago M. Mola <santi@mola.io> | 2016-11-23 15:30:34 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-23 15:38:12 +0100 |
commit | 08e08d771ef03df80248c80d81475fe7c5ea6fe7 (patch) | |
tree | d12e9befa22409e8cf50c5bbc4895e69fd8a5f48 /examples/custom_http_client | |
parent | 844169a739fb8bf1f252d416f10d8c7034db9fe2 (diff) | |
download | go-git-08e08d771ef03df80248c80d81475fe7c5ea6fe7.tar.gz |
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
Diffstat (limited to 'examples/custom_http_client')
-rw-r--r-- | examples/custom_http_client/main.go | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/examples/custom_http_client/main.go b/examples/custom_http_client/main.go deleted file mode 100644 index f28590f..0000000 --- a/examples/custom_http_client/main.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "crypto/tls" - "net/http" - "time" - - "github.com/fatih/color" - - git "gopkg.in/src-d/go-git.v4" - "gopkg.in/src-d/go-git.v4/plumbing/client" - githttp "gopkg.in/src-d/go-git.v4/plumbing/client/http" -) - -func main() { - // Create a custom http(s) client - customClient := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }, // accept any certificate (might be useful for testing) - Timeout: 15 * time.Second, // 15 second timeout - CheckRedirect: func(req *http.Request, via []*http.Request) error { // don't follow redirect - return http.ErrUseLastResponse - }, - } - // Override http(s) default protocol to use our custom client - clients.InstallProtocol( - "https", - githttp.NewGitUploadPackServiceFactory(customClient)) - - // Create an in-memory repository - r := git.NewMemoryRepository() - - const url = "https://github.com/git-fixtures/basic.git" - - // Clone repo - if err := r.Clone(&git.CloneOptions{URL: url}); err != nil { - panic(err) - } - - // Retrieve the branch pointed by HEAD - head, err := r.Head() - if err != nil { - panic(err) - } - - // Print latest commit - commit, err := r.Commit(head.Hash()) - if err != nil { - panic(err) - } - color.Green(commit.String()) - // Output: - // commit 6ecf0ef2c2dffb796033e5a02219af86ec6584e5 - // Author: Máximo Cuadros Ortiz <mcuadros@gmail.com> - // Date: Sun Apr 05 23:30:47 2015 +0200 - // - // vendor stuff -} |