mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 13:56:57 +00:00
create fastClient once
This commit is contained in:
parent
8add62ee2f
commit
4e42bca189
2 changed files with 4 additions and 3 deletions
|
@ -18,6 +18,7 @@ var ErrorNotFound = errors.New("not found")
|
|||
type Client struct {
|
||||
giteaRoot string
|
||||
giteaAPIToken string
|
||||
fastClient *fasthttp.Client
|
||||
infoTimeout time.Duration
|
||||
contentTimeout time.Duration
|
||||
}
|
||||
|
@ -38,6 +39,7 @@ func NewClient(giteaRoot, giteaAPIToken string) *Client {
|
|||
giteaAPIToken: giteaAPIToken,
|
||||
infoTimeout: 5 * time.Second,
|
||||
contentTimeout: 10 * time.Second,
|
||||
fastClient: getFastHTTPClient(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +113,7 @@ func (client *Client) do(timeout time.Duration, url string) (*fasthttp.Response,
|
|||
req.Header.Set(fasthttp.HeaderAuthorization, "token "+client.giteaAPIToken)
|
||||
res := fasthttp.AcquireResponse()
|
||||
|
||||
err := getFastHTTPClient(timeout).Do(req, res)
|
||||
err := client.fastClient.DoTimeout(req, res, timeout)
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
|
|
@ -6,9 +6,8 @@ import (
|
|||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func getFastHTTPClient(timeout time.Duration) *fasthttp.Client {
|
||||
func getFastHTTPClient() *fasthttp.Client {
|
||||
return &fasthttp.Client{
|
||||
ReadTimeout: timeout,
|
||||
MaxConnDuration: 60 * time.Second,
|
||||
MaxConnWaitTimeout: 1000 * time.Millisecond,
|
||||
MaxConnsPerHost: 128 * 16, // TODO: adjust bottlenecks for best performance with Gitea!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue