Skip to content

Commit 5f3cccf

Browse files
committed
docs: improve documentation for header transport and usage
- Add usage examples for `DefaultHeaderTransport` in comments - Add documentation for header format and usage in `RoundTrip` function Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 3973ff0 commit 5f3cccf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

provider/openai/client.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ type DefaultHeaderTransport struct {
1212
}
1313

1414
// RoundTrip implements the http.RoundTripper interface.
15+
// It adds the headers from DefaultHeaderTransport to the request before sending it.
16+
// Usage:
17+
// transport := &DefaultHeaderTransport{
18+
// Origin: http.DefaultTransport,
19+
// Header: http.Header{
20+
// "Authorization": {"Bearer token"},
21+
// },
22+
// }
23+
// client := &http.Client{Transport: transport}
24+
// resp, err := client.Get("https://example.com")
1525
func (t *DefaultHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) {
1626
for key, values := range t.Header {
1727
for _, value := range values {
@@ -22,6 +32,12 @@ func (t *DefaultHeaderTransport) RoundTrip(req *http.Request) (*http.Response, e
2232
}
2333

2434
// NewHeaders creates a new http.Header from the given slice of headers.
35+
// Each header in the slice should be in the format "key=value".
36+
// If a header is not in the correct format, it is skipped.
37+
// Usage:
38+
// headers := []string{"Authorization=Bearer token", "Content-Type=application/json"}
39+
// httpHeaders := NewHeaders(headers)
40+
// fmt.Println(httpHeaders.Get("Authorization")) // Output: Bearer token
2541
func NewHeaders(headers []string) http.Header {
2642
h := make(http.Header)
2743
for _, header := range headers {

0 commit comments

Comments
 (0)