@@ -2,41 +2,15 @@ package grok
22
33import (
44 "bytes"
5- "crypto/tls"
65 "encoding/json"
76 "fmt"
87 "io"
98 "net/http"
10- "sync"
11- "time"
129
10+ httpClient "github.com/dfanso/commit-msg/internal/http"
1311 "github.com/dfanso/commit-msg/pkg/types"
1412)
1513
16- var (
17- grokClientOnce sync.Once
18- grokClient * http.Client
19- )
20-
21- func getHTTPClient () * http.Client {
22- grokClientOnce .Do (func () {
23- transport := & http.Transport {
24- TLSHandshakeTimeout : 10 * time .Second ,
25- MaxIdleConns : 10 ,
26- IdleConnTimeout : 30 * time .Second ,
27- DisableCompression : true ,
28- TLSClientConfig : & tls.Config {
29- InsecureSkipVerify : false ,
30- },
31- }
32- grokClient = & http.Client {
33- Timeout : 30 * time .Second ,
34- Transport : transport ,
35- }
36- })
37- return grokClient
38- }
39-
4014// GenerateCommitMessage calls X.AI's Grok API to create a commit message from
4115// the provided Git diff and generation options.
4216func GenerateCommitMessage (config * types.Config , changes string , apiKey string , opts * types.GenerationOptions ) (string , error ) {
@@ -71,7 +45,7 @@ func GenerateCommitMessage(config *types.Config, changes string, apiKey string,
7145 req .Header .Set ("Content-Type" , "application/json" )
7246 req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , apiKey ))
7347
74- client := getHTTPClient ()
48+ client := httpClient . GetClient ()
7549 resp , err := client .Do (req )
7650 if err != nil {
7751 return "" , err
0 commit comments