mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-22 16:24:00 +01:00
use http.DefaultClient (#232)
This commit is contained in:
parent
05da87b50a
commit
a0dc68306b
@ -453,10 +453,6 @@ func GetServerHostname() string {
|
|||||||
return DefaultServerHostname
|
return DefaultServerHostname
|
||||||
}
|
}
|
||||||
|
|
||||||
func httpClient() *http.Client {
|
|
||||||
return &http.Client{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ApiGet(ctx context.Context, path string) ([]byte, error) {
|
func ApiGet(ctx context.Context, path string) ([]byte, error) {
|
||||||
if os.Getenv("HISHTORY_SIMULATE_NETWORK_ERROR") != "" {
|
if os.Getenv("HISHTORY_SIMULATE_NETWORK_ERROR") != "" {
|
||||||
return nil, fmt.Errorf("simulated network error: dial tcp: lookup api.hishtory.dev")
|
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-Version", "v0."+Version)
|
||||||
req.Header.Set("X-Hishtory-Device-Id", hctx.GetConf(ctx).DeviceId)
|
req.Header.Set("X-Hishtory-Device-Id", hctx.GetConf(ctx).DeviceId)
|
||||||
req.Header.Set("X-Hishtory-User-Id", data.UserId(hctx.GetConf(ctx).UserSecret))
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to GET %s%s: %w", GetServerHostname(), path, err)
|
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-Version", "v0."+Version)
|
||||||
req.Header.Set("X-Hishtory-Device-Id", hctx.GetConf(ctx).DeviceId)
|
req.Header.Set("X-Hishtory-Device-Id", hctx.GetConf(ctx).DeviceId)
|
||||||
req.Header.Set("X-Hishtory-User-Id", data.UserId(hctx.GetConf(ctx).UserSecret))
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to POST %s: %w", GetServerHostname()+path, err)
|
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 {
|
if apiKey == "" && apiEndpoint == DefaultOpenAiEndpoint {
|
||||||
return nil, OpenAiUsage{}, fmt.Errorf("OPENAI_API_KEY environment variable is not set")
|
return nil, OpenAiUsage{}, fmt.Errorf("OPENAI_API_KEY environment variable is not set")
|
||||||
}
|
}
|
||||||
client := &http.Client{}
|
|
||||||
apiReq := openAiRequest{
|
apiReq := openAiRequest{
|
||||||
Model: "gpt-3.5-turbo",
|
Model: "gpt-3.5-turbo",
|
||||||
NumberCompletions: numberCompletions,
|
NumberCompletions: numberCompletions,
|
||||||
@ -92,7 +91,7 @@ func GetAiSuggestionsViaOpenAiApi(apiEndpoint, query, shellName, osName string,
|
|||||||
if apiKey != "" {
|
if apiKey != "" {
|
||||||
req.Header.Set("Authorization", "Bearer "+apiKey)
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||||
}
|
}
|
||||||
resp, err := client.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, OpenAiUsage{}, fmt.Errorf("failed to query OpenAI API: %w", err)
|
return nil, OpenAiUsage{}, fmt.Errorf("failed to query OpenAI API: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user