refactor(http): implement shared transport and clients (#1288)

* fix(http): flip to a shared transport and clients

* nice threads

* that is terrible

* fake uri for magnet

* lazy locking

* why bother with r's

* flip magic params to struct

* refactor(http-clients): use separate clients with shared transport

* refactor(http-clients): add missing license header

* refactor(http-clients): defer and fix errors

---------

Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
Kyle Sanderson 2023-12-29 14:49:22 -08:00 committed by GitHub
parent 2a4fb7750b
commit 3234f0d919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 537 additions and 391 deletions

View file

@ -92,7 +92,7 @@ func (s *apiService) AddClient(indexer string, settings map[string]string) error
if !ok || key == "" {
return errors.New("api.Service.AddClient: could not initialize btn client: missing var 'api_key'")
}
s.apiClients[indexer] = btn.NewClient("", key)
s.apiClients[indexer] = btn.NewClient(key)
case "ptp":
user, ok := settings["api_user"]
@ -128,7 +128,7 @@ func (s *apiService) AddClient(indexer string, settings map[string]string) error
s.apiClients[indexer] = ops.NewClient(key)
case "mock":
s.apiClients[indexer] = mock.NewMockClient("", "mock")
s.apiClients[indexer] = mock.NewMockClient("mock")
default:
return errors.New("api.Service.AddClient: could not initialize client: unsupported indexer: %s", indexer)
@ -154,7 +154,7 @@ func (s *apiService) getClientForTest(req domain.IndexerTestApiRequest) (apiClie
if req.ApiKey == "" {
return nil, errors.New("api.Service.AddClient: could not initialize btn client: missing var 'api_key'")
}
return btn.NewClient("", req.ApiKey), nil
return btn.NewClient(req.ApiKey), nil
case "ptp":
if req.ApiUser == "" {
@ -185,7 +185,7 @@ func (s *apiService) getClientForTest(req domain.IndexerTestApiRequest) (apiClie
return ops.NewClient(req.ApiKey), nil
case "mock":
return mock.NewMockClient("", "mock"), nil
return mock.NewMockClient("mock"), nil
default:
return nil, errors.New("api.Service.AddClient: could not initialize client: unsupported indexer: %s", req.Identifier)