Go SDK API Reference
Client Methods
CreateClient
func NewClient(apiKey string, options ...ClientOption) (*Client, error)Initializes a new client with the provided API key and optional configuration.
- apiKey
- Your unique API key for authentication.
- options
- A variadic list of
ClientOption
functions to customize client behavior (e.g., timeout, base URL).
Returns a pointer to the initialized Client
object and an error if initialization fails.
GetResource
func (c *Client) GetResource(id string) (*Resource, error)Retrieves a specific resource by its unique identifier.
- id
- The unique identifier of the resource to fetch.
Returns a pointer to the Resource
object and an error if the request fails or the resource is not found.
ListResources
func (c *Client) ListResources(params ListResourcesParams) ([]Resource, error)Retrieves a list of resources, with optional filtering and pagination parameters.
- params
- A struct containing parameters for filtering, sorting, and pagination. See ListResourcesParams for details.
Returns a slice of Resource
objects and an error if the request fails.
CreateResource
func (c *Client) CreateResource(data CreateResourceData) (*Resource, error)Creates a new resource with the provided data.
- data
- A struct containing the data for the new resource.
Returns a pointer to the newly created Resource
object and an error if creation fails.
UpdateResource
func (c *Client) UpdateResource(id string, data UpdateResourceData) (*Resource, error)Updates an existing resource identified by its ID with new data.
- id
- The ID of the resource to update.
- data
- A struct containing the updated data for the resource.
Returns a pointer to the updated Resource
object and an error if the update fails.
DeleteResource
func (c *Client) DeleteResource(id string) errorDeletes a resource by its unique identifier.
- id
- The ID of the resource to delete.
Returns an error if the deletion fails.
Data Structures
ListResourcesParams
type ListResourcesParams struct {
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
SortBy string `json:"sortBy,omitempty"`
SortOrder string `json:"sortOrder,omitempty"`
FilterName string `json:"filterName,omitempty"`
}
Parameters for filtering, sorting, and paginating resource lists.
Limit
: Maximum number of resources to return.Offset
: Number of resources to skip.SortBy
: Field to sort by (e.g., "created_at", "name").SortOrder
: Order of sorting ("asc" or "desc").FilterName
: Filter resources by name.
Resource
type Resource struct {
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Data interface{} `json:"data,omitempty"`
}
Represents a single resource object.
CreateResourceData
type CreateResourceData struct {
Name string `json:"name"`
Data interface{} `json:"data,omitempty"`
}
Data required to create a new resource.
UpdateResourceData
type UpdateResourceData struct {
Name *string `json:"name,omitempty"`
Data *interface{} `json:"data,omitempty"`
}
Data for updating an existing resource. Fields are pointers to allow partial updates.
Client Options
Use these functions to customize the client's behavior:
WithTimeout
func WithTimeout(duration time.Duration) ClientOptionSets the HTTP request timeout for all client operations.
WithBaseURL
func WithBaseURL(url string) ClientOptionOverrides the default API base URL.
WithUserAgent
func WithUserAgent(userAgent string) ClientOptionSets a custom User-Agent header for requests.