use http.DefaultClient (#232)

This commit is contained in:
Pavel Griaznov 2024-08-11 18:20:29 +00:00 committed by GitHub
parent 05da87b50a
commit a0dc68306b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 8 deletions

View File

@ -453,10 +453,6 @@ func GetServerHostname() string {
return DefaultServerHostname
}
func httpClient() *http.Client {
return &http.Client{}
}
func ApiGet(ctx context.Context, path string) ([]byte, error) {
if os.Getenv("HISHTORY_SIMULATE_NETWORK_ERROR") != "" {
return nil, fmt.Errorf("simulated network error: dial tcp: lookup api.hishtory.dev")
@ -469,7 +465,7 @@ func ApiGet(ctx context.Context, path string) ([]byte, error) {
req.Header.Set("X-Hishtory-Version", "v0."+Version)
req.Header.Set("X-Hishtory-Device-Id", hctx.GetConf(ctx).DeviceId)
req.Header.Set("X-Hishtory-User-Id", data.UserId(hctx.GetConf(ctx).UserSecret))
resp, err := httpClient().Do(req)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to GET %s%s: %w", GetServerHostname(), path, err)
}
@ -499,7 +495,7 @@ func ApiPost(ctx context.Context, path, contentType string, reqBody []byte) ([]b
req.Header.Set("X-Hishtory-Version", "v0."+Version)
req.Header.Set("X-Hishtory-Device-Id", hctx.GetConf(ctx).DeviceId)
req.Header.Set("X-Hishtory-User-Id", data.UserId(hctx.GetConf(ctx).UserSecret))
resp, err := httpClient().Do(req)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to POST %s: %w", GetServerHostname()+path, err)
}

View File

@ -68,7 +68,6 @@ func GetAiSuggestionsViaOpenAiApi(apiEndpoint, query, shellName, osName string,
if apiKey == "" && apiEndpoint == DefaultOpenAiEndpoint {
return nil, OpenAiUsage{}, fmt.Errorf("OPENAI_API_KEY environment variable is not set")
}
client := &http.Client{}
apiReq := openAiRequest{
Model: "gpt-3.5-turbo",
NumberCompletions: numberCompletions,
@ -92,7 +91,7 @@ func GetAiSuggestionsViaOpenAiApi(apiEndpoint, query, shellName, osName string,
if apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
resp, err := client.Do(req)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, OpenAiUsage{}, fmt.Errorf("failed to query OpenAI API: %w", err)
}