main: use default HTTP client (proxy via env)
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
@@ -19,21 +18,10 @@ func main() {
|
||||
_ = godotenv.Load()
|
||||
|
||||
token := os.Getenv("BOT_TOKEN")
|
||||
proxyURL := os.Getenv("HTTP_PROXY")
|
||||
dbPath := getEnvDefault("DB_PATH", "db.sqlite3")
|
||||
|
||||
// Build HTTP client with optional proxy
|
||||
var httpClient *http.Client
|
||||
if proxyURL != "" {
|
||||
parsed, err := url.Parse(proxyURL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
tr := &http.Transport{Proxy: http.ProxyURL(parsed)}
|
||||
httpClient = &http.Client{Transport: tr}
|
||||
} else {
|
||||
httpClient = http.DefaultClient
|
||||
}
|
||||
// Default HTTP client respects HTTP_PROXY env var automatically
|
||||
httpClient := http.DefaultClient
|
||||
|
||||
botAPI, err := tgbotapi.NewBotAPIWithClient(token, "", httpClient)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user