Skip to content

Commit

Permalink
feat: Add a constructor for the Transport (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
unfunco authored May 4, 2024
1 parent 5c1335c commit 7707c5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ type Transport struct {
APIKey string
}

// NewTransport constructs and returns a new Transport struct that includes the
// given API key as a header in each request.
func NewTransport(apiKey string) *Transport {
return &Transport{APIKey: apiKey}
}

// Client returns an HTTP client that will include the API key in the request,
// and is safe for concurrent use by multiple goroutines.
func (t *Transport) Client() *http.Client {
Expand Down
10 changes: 10 additions & 0 deletions transport_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
package anthropic

import "testing"

func TestNewTransport(t *testing.T) {
apiKey := "test-api-key"
transport := NewTransport(apiKey)
if transport.APIKey != apiKey {
t.Errorf("transport.APIKey = %q, want %q", transport.APIKey, apiKey)
}
}

0 comments on commit 7707c5f

Please sign in to comment.