Files
onspring-api-sdk-go/ping.go
T
Stevan Freeborn a9e49906e0 feat: initialize client core and ping endpoint
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.
2025-12-05 21:33:23 -06:00

47 lines
1.1 KiB
Go

package onspring
import (
"context"
"net/http"
)
const (
// pingPath is the API endpoint path for the ping health check.
pingPath = "/ping"
)
// PingEndpoint provides access to the Onspring API ping endpoint.
// It can be used to verify API connectivity and authentication.
type PingEndpoint struct {
// client is the parent Client used to make API requests.
client *Client
}
// Get performs a ping request to verify API connectivity.
// This is a simple health check that can be used to test if the API is
// reachable.
//
// Parameters:
// - ctx: The context for the request
//
// Returns:
// - error: nil if the ping succeeds, or an error if the request fails
// or authentication is invalid
//
// Example:
//
// client := onspring.NewClient("your-api-key")
// err := client.Ping.Get(context.Background())
// if err != nil {
// log.Fatal("Ping failed:", err)
// }
func (p *PingEndpoint) Get(ctx context.Context) error {
req, err := p.client.newRequest(ctx, http.MethodGet, pingPath, nil)
if err != nil {
return err
}
return p.client.do(req)
}