mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
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:
parent
2a4fb7750b
commit
3234f0d919
48 changed files with 537 additions and 391 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
"github.com/autobrr/autobrr/pkg/sharedhttp"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
@ -26,6 +27,8 @@ type lunaSeaSender struct {
|
|||
log zerolog.Logger
|
||||
Settings domain.Notification
|
||||
builder NotificationBuilderPlainText
|
||||
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
func (s *lunaSeaSender) rewriteWebhookURL(url string) string {
|
||||
|
@ -38,6 +41,10 @@ func NewLunaSeaSender(log zerolog.Logger, settings domain.Notification) domain.N
|
|||
log: log.With().Str("sender", "lunasea").Logger(),
|
||||
Settings: settings,
|
||||
builder: NotificationBuilderPlainText{},
|
||||
httpClient: &http.Client{
|
||||
Timeout: time.Second * 30,
|
||||
Transport: sharedhttp.Transport,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,8 +71,7 @@ func (s *lunaSeaSender) Send(event domain.NotificationEvent, payload domain.Noti
|
|||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
res, err := client.Do(req)
|
||||
res, err := s.httpClient.Do(req)
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Msg("lunasea client request error")
|
||||
return errors.Wrap(err, "could not make request")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue