Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/api/client/debug.go
3431 views
1
package client
2
3
import (
4
"github.com/kardolus/chatgpt-cli/internal"
5
"go.uber.org/zap"
6
"strings"
7
)
8
9
func (c *Client) printRequestDebugInfo(endpoint string, body []byte, headers map[string]string) {
10
sugar := zap.S()
11
sugar.Debugf("\nGenerated cURL command:\n")
12
13
method := "POST"
14
if body == nil {
15
method = "GET"
16
}
17
sugar.Debugf("curl --location --insecure --request %s '%s' \\", method, endpoint)
18
19
if len(headers) > 0 {
20
for k, v := range headers {
21
sugar.Debugf(" --header '%s: %s' \\", k, v)
22
}
23
} else {
24
sugar.Debugf(" --header \"%s: %s${%s_API_KEY}\" \\", c.Config.AuthHeader, c.Config.AuthTokenPrefix, strings.ToUpper(c.Config.Name))
25
sugar.Debugf(" --header '%s: %s' \\", internal.HeaderContentTypeKey, internal.HeaderContentTypeValue)
26
sugar.Debugf(" --header '%s: %s' \\", internal.HeaderUserAgentKey, c.Config.UserAgent)
27
28
// Include custom headers from config
29
for k, v := range c.Config.CustomHeaders {
30
sugar.Debugf(" --header '%s: %s' \\", k, v)
31
}
32
}
33
34
if body != nil {
35
bodyString := strings.ReplaceAll(string(body), "'", "'\"'\"'")
36
sugar.Debugf(" --data-raw '%s'", bodyString)
37
}
38
}
39
40
func (c *Client) printResponseDebugInfo(raw []byte) {
41
sugar := zap.S()
42
sugar.Debugf("\nResponse\n")
43
sugar.Debugf("%s\n", raw)
44
}
45
46