feat: init client

This commit is contained in:
2025-08-12 18:38:22 +02:00
commit a145da0d2d
24 changed files with 713 additions and 0 deletions

61
client/client_builder.go Normal file
View File

@@ -0,0 +1,61 @@
package client
import "net/http"
// Builder is a builder for creating a TCGDexClient with customizable options.
type Builder struct {
language *string
baseURL *string
httpClient *http.Client
}
// NewBuilder creates a new Builder instance.
// This allows for fluent configuration of the TCGDexClient.
func NewBuilder() *Builder {
return &Builder{}
}
// Language sets the language for the TCGDexClient.
func (b *Builder) Language(language string) *Builder {
b.language = &language
return b
}
// BaseURL sets the base URL for the TCGDexClient.
func (b *Builder) BaseURL(baseURL string) *Builder {
b.baseURL = &baseURL
return b
}
// HTTPClient sets the custom HTTP client for the TCGDexClient.
func (b *Builder) HTTPClient(client *http.Client) *Builder {
b.httpClient = client
return b
}
// Builder constructs the TCGDexClient with the specified options.
func (b *Builder) Builder() TCGDexClient {
httpClient := b.httpClient
if httpClient == nil {
httpClient = http.DefaultClient
}
language := b.language
if language == nil {
language = ptr(defaultLanguage)
}
baseURL := b.baseURL
if baseURL == nil {
baseURL = ptr(defaultURL)
}
return NewClientWithCustomHTTPClient(*baseURL, *language, httpClient)
}
func ptr[T any](s T) *T {
return &s
}