diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-11-05 19:08:20 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-11-05 20:55:46 +0100 |
commit | 6be0bc1233b1a31e749354f1d54104b49d5bf19b (patch) | |
tree | a9fd259944a42322050247ed6b5393150f2c4cb8 /remote.go | |
parent | a80d56b21142096f458758405736f3d567c175f5 (diff) | |
download | go-git-6be0bc1233b1a31e749354f1d54104b49d5bf19b.tar.gz |
clients: new AuthMethod and ConnectWithAuth
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -11,13 +11,20 @@ import ( type Remote struct { Endpoint common.Endpoint + Auth common.AuthMethod - upSrv clients.GitUploadPackService + upSrv common.GitUploadPackService upInfo *common.GitUploadPackInfo } // NewRemote returns a new Remote, using as client http.DefaultClient func NewRemote(url string) (*Remote, error) { + return NewAuthenticatedRemote(url, nil) +} + +// NewAuthenticatedRemote returns a new Remote using the given AuthMethod, using as +// client http.DefaultClient +func NewAuthenticatedRemote(url string, auth common.AuthMethod) (*Remote, error) { end, err := common.NewEndpoint(url) if err != nil { return nil, err @@ -25,16 +32,28 @@ func NewRemote(url string) (*Remote, error) { return &Remote{ Endpoint: end, + Auth: auth, upSrv: clients.NewGitUploadPackService(), }, nil } // Connect with the endpoint func (r *Remote) Connect() error { - if err := r.upSrv.Connect(r.Endpoint); err != nil { + var err error + if r.Auth == nil { + err = r.upSrv.Connect(r.Endpoint) + } else { + err = r.upSrv.ConnectWithAuth(r.Endpoint, r.Auth) + } + + if err != nil { return err } + return r.retrieveUpInfo() +} + +func (r *Remote) retrieveUpInfo() error { var err error if r.upInfo, err = r.upSrv.Info(); err != nil { return err |