Add comprehensive documentation comments

This commit is contained in:
Oliver Jakoubek 2025-11-18 18:36:48 +01:00
commit 9db82f92c5
6 changed files with 128 additions and 26 deletions

View file

@ -5,20 +5,49 @@ import (
"time"
)
// Option is a function type that modifies a Client during initialization.
// Options follow the functional options pattern for configuring client behavior.
type Option func(*Client)
// WithBaseURL returns an Option that sets a custom API base URL for the client.
// Use this to point to a different Sendamatic API endpoint or a testing environment.
//
// Example:
//
// client := sendamatic.NewClient("user", "pass",
// sendamatic.WithBaseURL("https://custom.api.url"))
func WithBaseURL(baseURL string) Option {
return func(c *Client) {
c.baseURL = baseURL
}
}
// WithHTTPClient returns an Option that replaces the default HTTP client with a custom one.
// This allows full control over HTTP behavior such as transport settings, connection pooling,
// and custom middleware.
//
// Example:
//
// customClient := &http.Client{
// Timeout: 60 * time.Second,
// Transport: customTransport,
// }
// client := sendamatic.NewClient("user", "pass",
// sendamatic.WithHTTPClient(customClient))
func WithHTTPClient(client *http.Client) Option {
return func(c *Client) {
c.httpClient = client
}
}
// WithTimeout returns an Option that sets the HTTP client timeout duration.
// This determines how long the client will wait for a response before timing out.
// The default timeout is 30 seconds.
//
// Example:
//
// client := sendamatic.NewClient("user", "pass",
// sendamatic.WithTimeout(60*time.Second))
func WithTimeout(timeout time.Duration) Option {
return func(c *Client) {
c.httpClient.Timeout = timeout