mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-25 17:53:24 +01:00
use http.DefaultClient (#232)
This commit is contained in:
parent
05da87b50a
commit
a0dc68306b
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user