diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-13 20:07:21 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-13 20:07:21 +0200 |
commit | a65bcbc63bef24cf219c63d1b8cfb309c95d1c0f (patch) | |
tree | 973644feaf08adc916dab8fb95d1f6c86194c9c1 /clients/http/git_upload_pack.go | |
parent | a6ea9e8dd2eda48c8405f609e0fb444d3717af53 (diff) | |
download | go-git-a65bcbc63bef24cf219c63d1b8cfb309c95d1c0f.tar.gz |
clients: new Endpoint implementation and InstallProtocol function
Diffstat (limited to 'clients/http/git_upload_pack.go')
-rw-r--r-- | clients/http/git_upload_pack.go | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go index 860318f..96535de 100644 --- a/clients/http/git_upload_pack.go +++ b/clients/http/git_upload_pack.go @@ -12,37 +12,38 @@ import ( ) type GitUploadPackService struct { - Client *http.Client - + client *http.Client endpoint common.Endpoint auth HTTPAuthMethod } -func NewGitUploadPackService() *GitUploadPackService { +func NewGitUploadPackService(endpoint common.Endpoint) common.GitUploadPackService { return &GitUploadPackService{ - Client: http.DefaultClient, + client: http.DefaultClient, + endpoint: endpoint, } } -func (s *GitUploadPackService) Connect(url common.Endpoint) error { - s.endpoint = url +func (s *GitUploadPackService) Connect() error { return nil } -func (s *GitUploadPackService) ConnectWithAuth(url common.Endpoint, auth common.AuthMethod) error { +func (s *GitUploadPackService) ConnectWithAuth(auth common.AuthMethod) error { httpAuth, ok := auth.(HTTPAuthMethod) if !ok { - return InvalidAuthMethodErr + return common.ErrInvalidAuthMethod } - s.endpoint = url s.auth = httpAuth - return nil } func (s *GitUploadPackService) Info() (*common.GitUploadPackInfo, error) { - url := fmt.Sprintf("%s/info/refs?service=%s", s.endpoint, common.GitUploadPackServiceName) + url := fmt.Sprintf( + "%s/info/refs?service=%s", + s.endpoint.String(), common.GitUploadPackServiceName, + ) + res, err := s.doRequest("GET", url, nil) if err != nil { return nil, err @@ -55,7 +56,11 @@ func (s *GitUploadPackService) Info() (*common.GitUploadPackInfo, error) { } func (s *GitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadCloser, error) { - url := fmt.Sprintf("%s/%s", s.endpoint, common.GitUploadPackServiceName) + url := fmt.Sprintf( + "%s/%s", + s.endpoint.String(), common.GitUploadPackServiceName, + ) + res, err := s.doRequest("POST", url, r.Reader()) if err != nil { return nil, err @@ -83,7 +88,7 @@ func (s *GitUploadPackService) doRequest(method, url string, content *strings.Re s.applyHeadersToRequest(req, content) s.applyAuthToRequest(req) - res, err := s.Client.Do(req) + res, err := s.client.Do(req) if err != nil { return nil, core.NewUnexpectedError(err) } |