Skip to content

Commit

Permalink
docs: improve documentation and testing across multiple modules
Browse files Browse the repository at this point in the history
- Add usage comments for DefaultHeaderTransport in client.go
- Add args and returns comments for IsCommandAvailable function in util.go

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Jan 29, 2025
1 parent 478b792 commit 5f210d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 13 additions & 11 deletions provider/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ type DefaultHeaderTransport struct {
// RoundTrip implements the http.RoundTripper interface.
// It adds the headers from DefaultHeaderTransport to the request before sending it.
// Usage:
// transport := &DefaultHeaderTransport{
// Origin: http.DefaultTransport,
// Header: http.Header{
// "Authorization": {"Bearer token"},
// },
// }
// client := &http.Client{Transport: transport}
// resp, err := client.Get("https://example.com")
//
// transport := &DefaultHeaderTransport{
// Origin: http.DefaultTransport,
// Header: http.Header{
// "Authorization": {"Bearer token"},
// },
// }
// client := &http.Client{Transport: transport}
// resp, err := client.Get("https://example.com")
func (t *DefaultHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) {
for key, values := range t.Header {
for _, value := range values {
Expand All @@ -35,9 +36,10 @@ func (t *DefaultHeaderTransport) RoundTrip(req *http.Request) (*http.Response, e
// Each header in the slice should be in the format "key=value".
// If a header is not in the correct format, it is skipped.
// Usage:
// headers := []string{"Authorization=Bearer token", "Content-Type=application/json"}
// httpHeaders := NewHeaders(headers)
// fmt.Println(httpHeaders.Get("Authorization")) // Output: Bearer token
//
// headers := []string{"Authorization=Bearer token", "Content-Type=application/json"}
// httpHeaders := NewHeaders(headers)
// fmt.Println(httpHeaders.Get("Authorization")) // Output: Bearer token
func NewHeaders(headers []string) http.Header {
h := make(http.Header)
for _, header := range headers {
Expand Down
6 changes: 4 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ func IsCommandAvailable(cmd string) bool {
// The resulting map contains the keys and values from the input slice.
//
// Args:
// args ([]string): A slice of strings where each string is in the format "key=value".
//
// args ([]string): A slice of strings where each string is in the format "key=value".
//
// Returns:
// Data: A map where the keys and values are derived from the input slice.
//
// Data: A map where the keys and values are derived from the input slice.
func ConvertToMap(args []string) Data {
m := make(Data)
for _, arg := range args {
Expand Down

0 comments on commit 5f210d4

Please sign in to comment.