From a310d7e6d4d233e9624edcb3839b4d6c282cfc52 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Sat, 21 Mar 2026 12:11:36 +0700 Subject: [PATCH] Add telemtClient to bot struct and implement makeDirectTransport function for enhanced HTTP client configuration in main.go. --- main.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b84816c..b2be838 100644 --- a/main.go +++ b/main.go @@ -46,6 +46,7 @@ type config struct { type bot struct { cfg config httpClient *http.Client + telemtClient *http.Client telegramBase string offset int64 } @@ -158,6 +159,17 @@ func makeHTTPTransport() (*http.Transport, error) { return tr, nil } +func makeDirectTransport() *http.Transport { + return &http.Transport{ + MaxIdleConns: 16, + MaxIdleConnsPerHost: 8, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 5 * time.Second, + ForceAttemptHTTP2: true, + DisableCompression: false, + } +} + func getProxyURL() string { for _, key := range []string{"ALL_PROXY", "all_proxy", "HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"} { if v := strings.TrimSpace(os.Getenv(key)); v != "" { @@ -183,9 +195,15 @@ func main() { Timeout: cfg.TelegramTimeout, } + telemtClient := &http.Client{ + Transport: makeDirectTransport(), + Timeout: cfg.TelemtTimeout, + } + b := &bot{ cfg: cfg, httpClient: httpClient, + telemtClient: telemtClient, telegramBase: "https://api.telegram.org/bot" + cfg.TelegramBotToken, } @@ -611,7 +629,7 @@ func (b *bot) callTelemtJSON(ctx context.Context, method, path string, payload a req.Header.Set("Authorization", b.cfg.TelemtAPIAuth) } - resp, err := b.httpClient.Do(req) + resp, err := b.telemtClient.Do(req) if err != nil { return err }