chore(webhooks): reuse webhook client
This commit is contained in:
parent
c3947e1016
commit
ec4aa606e2
@ -37,6 +37,8 @@ import (
|
|||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var webhookClient *http.Client
|
||||||
|
|
||||||
type Webhook struct {
|
type Webhook struct {
|
||||||
ID int64 `xorm:"bigint autoincr not null unique pk" json:"id" param:"webhook"`
|
ID int64 `xorm:"bigint autoincr not null unique pk" json:"id" param:"webhook"`
|
||||||
TargetURL string `xorm:"not null" valid:"minstringlength(1)" minLength:"1" json:"target_url"`
|
TargetURL string `xorm:"not null" valid:"minstringlength(1)" minLength:"1" json:"target_url"`
|
||||||
@ -142,10 +144,16 @@ func (w *Webhook) Delete(s *xorm.Session, a web.Auth) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getWebhookHTTPClient() (client *http.Client) {
|
func getWebhookHTTPClient() (client *http.Client) {
|
||||||
|
|
||||||
|
if webhookClient != nil {
|
||||||
|
return webhookClient
|
||||||
|
}
|
||||||
|
|
||||||
client = http.DefaultClient
|
client = http.DefaultClient
|
||||||
client.Timeout = time.Duration(config.WebhooksTimeoutSeconds.GetInt()) * time.Second
|
client.Timeout = time.Duration(config.WebhooksTimeoutSeconds.GetInt()) * time.Second
|
||||||
|
|
||||||
if config.WebhooksProxyURL.GetString() == "" || config.WebhooksProxyPassword.GetString() == "" {
|
if config.WebhooksProxyURL.GetString() == "" || config.WebhooksProxyPassword.GetString() == "" {
|
||||||
|
webhookClient = client
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +167,8 @@ func getWebhookHTTPClient() (client *http.Client) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webhookClient = client
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user