Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a constructor for the Transport #18

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading