mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-09-05 07:36:36 +08:00
fix: add context to HTTP request in getToken and simplify HTTP client initialization
This commit is contained in:
@@ -18,7 +18,7 @@ func (a *Alist) getToken(ctx context.Context) error {
|
|||||||
return fmt.Errorf("failed to marshal login request: %w", err)
|
return fmt.Errorf("failed to marshal login request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPost, a.baseURL+"/api/auth/login", bytes.NewBuffer(loginBody))
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, a.baseURL+"/api/auth/login", bytes.NewBuffer(loginBody))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create login request: %w", err)
|
return fmt.Errorf("failed to create login request: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
httpClient *http.Client
|
|
||||||
)
|
|
||||||
|
|
||||||
func getHttpClient() *http.Client {
|
func getHttpClient() *http.Client {
|
||||||
if httpClient != nil {
|
return &http.Client{
|
||||||
return httpClient
|
|
||||||
}
|
|
||||||
httpClient = &http.Client{
|
|
||||||
Timeout: 12 * time.Hour,
|
Timeout: 12 * time.Hour,
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return httpClient
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user