establishes the foundational architecture for the Onspring Go SDK. changes included: - add `Client` struct and `NewClient` constructor with authentication. - implement functional options pattern (WithHTTPClient, WithBaseURL, etc.). - add `OnspringAPIError` type for handling non-2xx responses. - implement internal request construction and execution logic. - add `Ping` service for API health check verification. - add comprehensive unit tests and mock server infrastructure.
31 lines
819 B
Go
31 lines
819 B
Go
package onspring
|
|
|
|
import "net/http"
|
|
|
|
// Option is a functional option for configuring a Client.
|
|
type Option func(*Client)
|
|
|
|
// WithHTTPClient sets a custom HTTP client for the Onspring client.
|
|
// If not provided, the client will use http.DefaultClient.
|
|
func WithHTTPClient(client *http.Client) Option {
|
|
return func(c *Client) {
|
|
c.httpClient = client
|
|
}
|
|
}
|
|
|
|
// WithBaseURL sets a custom base URL for the Onspring API.
|
|
// This is useful for testing or when using a different Onspring environment.
|
|
func WithBaseURL(url string) Option {
|
|
return func(c *Client) {
|
|
c.baseURL = url
|
|
}
|
|
}
|
|
|
|
// WithAPIVersion sets a custom API version for the Onspring client.
|
|
// If not provided, the client will use the default API version.
|
|
func WithAPIVersion(version string) Option {
|
|
return func(c *Client) {
|
|
c.apiVersion = version
|
|
}
|
|
}
|