Documentation
¶
Overview ¶
Package client provides a comprehensive API client for interacting with the Talis API.
This package offers a clean, idiomatic Go interface for all Talis API operations, including instance management, user administration, project operations, and task handling. The client handles authentication, request formatting, response parsing, and error management, allowing developers to focus on their application logic rather than API communication details.
Basic usage:
// Create a client with default options
client, err := client.NewClient(nil)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Set API key if needed
client.SetAPIKey("your-api-key")
// Use the client to interact with the API
instances, err := client.GetInstances(context.Background(), nil)
For more detailed examples, refer to the client_usage.md documentation.
Index ¶
- Constants
- type APIClient
- func (c *APIClient) AdminGetInstances(ctx context.Context) ([]*models.Instance, error)
- func (c *APIClient) AdminGetInstancesMetadata(ctx context.Context) ([]*models.Instance, error)
- func (c *APIClient) CreateInstance(ctx context.Context, req []types.InstanceRequest) ([]*models.Instance, error)
- func (c *APIClient) CreateProject(ctx context.Context, params handlers.ProjectCreateParams) (models.Project, error)
- func (c *APIClient) CreateUser(ctx context.Context, params handlers.CreateUserParams) (types.CreateUserResponse, error)
- func (c *APIClient) DeleteInstances(ctx context.Context, req types.DeleteInstancesRequest) error
- func (c *APIClient) DeleteProject(ctx context.Context, params handlers.ProjectDeleteParams) error
- func (c *APIClient) DeleteUser(ctx context.Context, params handlers.DeleteUserParams) error
- func (c *APIClient) GetInstance(ctx context.Context, id string) (models.Instance, error)
- func (c *APIClient) GetInstances(ctx context.Context, opts *models.ListOptions) ([]*models.Instance, error)
- func (c *APIClient) GetInstancesMetadata(ctx context.Context, opts *models.ListOptions) ([]*models.Instance, error)
- func (c *APIClient) GetInstancesPublicIPs(ctx context.Context, opts *models.ListOptions) (types.PublicIPsResponse, error)
- func (c *APIClient) GetProject(ctx context.Context, params handlers.ProjectGetParams) (models.Project, error)
- func (c *APIClient) GetTask(ctx context.Context, params handlers.TaskGetParams) (models.Task, error)
- func (c *APIClient) GetUserByID(ctx context.Context, params handlers.UserGetByIDParams) (models.User, error)
- func (c *APIClient) GetUsers(ctx context.Context, params handlers.UserGetParams) (types.UserResponse, error)
- func (c *APIClient) HealthCheck(ctx context.Context) (map[string]string, error)
- func (c *APIClient) ListProjectInstances(ctx context.Context, params handlers.ProjectListInstancesParams) ([]*models.Instance, error)
- func (c *APIClient) ListProjects(ctx context.Context, params handlers.ProjectListParams) ([]*models.Project, error)
- func (c *APIClient) ListTasks(ctx context.Context, params handlers.TaskListParams) ([]*models.Task, error)
- func (c *APIClient) ListTasksByInstanceID(ctx context.Context, ownerID uint, instanceID uint, actionFilter string, ...) ([]*models.Task, error)
- func (c *APIClient) SetAPIKey(apiKey string)
- func (c *APIClient) TerminateTask(ctx context.Context, params handlers.TaskTerminateParams) error
- func (c *APIClient) UpdateTaskStatus(ctx context.Context, params handlers.TaskUpdateStatusParams) error
- type Client
- type Options
Constants ¶
const DefaultTimeout = 30 * time.Second
DefaultTimeout is the default timeout for API requests
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIClient ¶
type APIClient struct {
// AuthToken is a JWT token for authentication (if used)
AuthToken string
// APIKey is the API key for authentication
APIKey string
// contains filtered or unexported fields
}
APIClient implements the Client interface. It handles the actual HTTP communication with the Talis API, including request formatting, authentication, and response parsing.
func (*APIClient) AdminGetInstances ¶
AdminGetInstances retrieves all instances
func (*APIClient) AdminGetInstancesMetadata ¶
AdminGetInstancesMetadata retrieves metadata for all instances
func (*APIClient) CreateInstance ¶
func (c *APIClient) CreateInstance(ctx context.Context, req []types.InstanceRequest) ([]*models.Instance, error)
CreateInstance creates new instances
func (*APIClient) CreateProject ¶
func (c *APIClient) CreateProject(ctx context.Context, params handlers.ProjectCreateParams) (models.Project, error)
CreateProject creates a new project
func (*APIClient) CreateUser ¶
func (c *APIClient) CreateUser(ctx context.Context, params handlers.CreateUserParams) (types.CreateUserResponse, error)
CreateUser creates a new user
func (*APIClient) DeleteInstances ¶ added in v0.0.6
DeleteInstances deletes specified instances for a project
func (*APIClient) DeleteProject ¶
DeleteProject deletes a project by name
func (*APIClient) DeleteUser ¶
DeleteUser user deletes a user
func (*APIClient) GetInstance ¶
GetInstance retrieves an instance by ID
func (*APIClient) GetInstances ¶
func (c *APIClient) GetInstances(ctx context.Context, opts *models.ListOptions) ([]*models.Instance, error)
GetInstances lists instances with optional filtering
func (*APIClient) GetInstancesMetadata ¶
func (c *APIClient) GetInstancesMetadata(ctx context.Context, opts *models.ListOptions) ([]*models.Instance, error)
GetInstancesMetadata retrieves metadata for all instances
func (*APIClient) GetInstancesPublicIPs ¶
func (c *APIClient) GetInstancesPublicIPs(ctx context.Context, opts *models.ListOptions) (types.PublicIPsResponse, error)
GetInstancesPublicIPs retrieves public IPs for all instances
func (*APIClient) GetProject ¶
func (c *APIClient) GetProject(ctx context.Context, params handlers.ProjectGetParams) (models.Project, error)
GetProject retrieves a project by name
func (*APIClient) GetTask ¶
func (c *APIClient) GetTask(ctx context.Context, params handlers.TaskGetParams) (models.Task, error)
GetTask retrieves a task by name
func (*APIClient) GetUserByID ¶
func (c *APIClient) GetUserByID(ctx context.Context, params handlers.UserGetByIDParams) (models.User, error)
GetUserByID retrieves a user by id
func (*APIClient) GetUsers ¶
func (c *APIClient) GetUsers(ctx context.Context, params handlers.UserGetParams) (types.UserResponse, error)
GetUsers retrieves a user by username
func (*APIClient) HealthCheck ¶
HealthCheck checks the health of the API
func (*APIClient) ListProjectInstances ¶
func (c *APIClient) ListProjectInstances(ctx context.Context, params handlers.ProjectListInstancesParams) ([]*models.Instance, error)
ListProjectInstances lists all instances for a project
func (*APIClient) ListProjects ¶
func (c *APIClient) ListProjects(ctx context.Context, params handlers.ProjectListParams) ([]*models.Project, error)
ListProjects lists all projects
func (*APIClient) ListTasks ¶
func (c *APIClient) ListTasks(ctx context.Context, params handlers.TaskListParams) ([]*models.Task, error)
ListTasks lists all tasks
func (*APIClient) ListTasksByInstanceID ¶ added in v0.0.8
func (c *APIClient) ListTasksByInstanceID(ctx context.Context, ownerID uint, instanceID uint, actionFilter string, opts *models.ListOptions) ([]*models.Task, error)
ListTasksByInstanceID retrieves tasks for a specific instance ID, with optional action and pagination.
func (*APIClient) SetAPIKey ¶ added in v0.0.7
SetAPIKey sets the API key for the client. This method can be used to update the API key after client creation.
func (*APIClient) TerminateTask ¶
TerminateTask terminates a task by name
func (*APIClient) UpdateTaskStatus ¶
func (c *APIClient) UpdateTaskStatus(ctx context.Context, params handlers.TaskUpdateStatusParams) error
UpdateTaskStatus updates the status of a task
type Client ¶
type Client interface {
// AdminGetInstances retrieves all instances across all projects.
// This is an administrative endpoint that returns all instances regardless of owner.
// Returns a slice of Instance pointers and any error encountered.
AdminGetInstances(ctx context.Context) ([]*models.Instance, error)
// AdminGetInstancesMetadata retrieves metadata for all instances across all projects.
// This is an administrative endpoint that returns lightweight instance information.
// Returns a slice of Instance pointers containing only metadata fields and any error encountered.
AdminGetInstancesMetadata(ctx context.Context) ([]*models.Instance, error)
// HealthCheck performs a health check against the API.
// Returns a map of component names to their status and any error encountered.
// A successful response typically includes entries like {"status": "ok"}.
HealthCheck(ctx context.Context) (map[string]string, error)
// GetInstances retrieves instances with optional filtering via ListOptions.
// The opts parameter can include pagination (limit/offset), status filtering,
// and whether to include deleted instances.
// Returns a slice of Instance pointers and any error encountered.
GetInstances(ctx context.Context, opts *models.ListOptions) ([]*models.Instance, error)
// GetInstancesMetadata retrieves metadata for instances with optional filtering.
// Similar to GetInstances but returns only essential metadata fields for efficiency.
// Returns a slice of Instance pointers with metadata fields and any error encountered.
GetInstancesMetadata(ctx context.Context, opts *models.ListOptions) ([]*models.Instance, error)
// GetInstancesPublicIPs retrieves public IP addresses for instances with optional filtering.
// Returns a PublicIPsResponse containing a map of instance IDs to their public IPs,
// and any error encountered.
GetInstancesPublicIPs(ctx context.Context, opts *models.ListOptions) (types.PublicIPsResponse, error)
// GetInstance retrieves a specific instance by its ID.
// Returns the Instance and any error encountered.
GetInstance(ctx context.Context, id string) (models.Instance, error)
// CreateInstance creates new instances based on the provided specifications.
// The req parameter is a slice of InstanceRequest objects, each describing
// an instance to be created.
// Returns a slice of the created Instance pointers and any error encountered.
CreateInstance(ctx context.Context, req []types.InstanceRequest) ([]*models.Instance, error)
// DeleteInstances terminates the specified instances for a project.
// The req parameter contains the project name and instance IDs to delete.
// Returns an error if the operation fails.
DeleteInstances(ctx context.Context, req types.DeleteInstancesRequest) error
// GetUserByID retrieves a user by their ID.
// Returns the User and any error encountered.
GetUserByID(ctx context.Context, params handlers.UserGetByIDParams) (models.User, error)
// GetUsers retrieves users based on the provided parameters.
// Returns a UserResponse containing user information and any error encountered.
GetUsers(ctx context.Context, params handlers.UserGetParams) (types.UserResponse, error)
// CreateUser creates a new user with the provided parameters.
// Returns a CreateUserResponse containing the created user information and any error encountered.
CreateUser(ctx context.Context, params handlers.CreateUserParams) (types.CreateUserResponse, error)
// DeleteUser deletes a user based on the provided parameters.
// Returns an error if the operation fails.
DeleteUser(ctx context.Context, params handlers.DeleteUserParams) error
// CreateProject creates a new project with the provided parameters.
// Returns the created Project and any error encountered.
CreateProject(ctx context.Context, params handlers.ProjectCreateParams) (models.Project, error)
// GetProject retrieves a project by name.
// Returns the Project and any error encountered.
GetProject(ctx context.Context, params handlers.ProjectGetParams) (models.Project, error)
// ListProjects lists all projects based on the provided parameters.
// Returns a slice of Project pointers and any error encountered.
ListProjects(ctx context.Context, params handlers.ProjectListParams) ([]*models.Project, error)
// DeleteProject deletes a project by name.
// Returns an error if the operation fails.
DeleteProject(ctx context.Context, params handlers.ProjectDeleteParams) error
// ListProjectInstances lists all instances for a specific project.
// Returns a slice of Instance pointers and any error encountered.
ListProjectInstances(ctx context.Context, params handlers.ProjectListInstancesParams) ([]*models.Instance, error)
// GetTask retrieves a task by its identifier.
// Returns the Task and any error encountered.
GetTask(ctx context.Context, params handlers.TaskGetParams) (models.Task, error)
// ListTasks lists all tasks based on the provided parameters.
// Returns a slice of Task pointers and any error encountered.
ListTasks(ctx context.Context, params handlers.TaskListParams) ([]*models.Task, error)
// ListTasksByInstanceID retrieves tasks for a specific instance ID.
// Parameters:
// - ownerID: The ID of the user who owns the instance
// - instanceID: The ID of the instance to list tasks for
// - actionFilter: Optional filter for task action type (e.g., "create_instances")
// - opts: Optional pagination parameters
// Returns a slice of Task pointers and any error encountered.
ListTasksByInstanceID(ctx context.Context, ownerID uint, instanceID uint, actionFilter string, opts *models.ListOptions) ([]*models.Task, error)
// TerminateTask terminates a running task.
// Returns an error if the operation fails.
TerminateTask(ctx context.Context, params handlers.TaskTerminateParams) error
// UpdateTaskStatus updates the status of a task.
// Returns an error if the operation fails.
UpdateTaskStatus(ctx context.Context, params handlers.TaskUpdateStatusParams) error
}
Client is the interface for the Talis API client. It provides methods for interacting with all aspects of the Talis API, organized into logical categories: - Admin operations (for administrative access) - Health checks (for monitoring API status) - Instance management (creating, listing, and deleting compute instances) - User management (creating, retrieving, and deleting users) - Project management (creating, retrieving, and deleting projects) - Task management (retrieving and managing long-running tasks)
All methods accept a context.Context as their first parameter to support timeout and cancellation. Most methods return structured data and an error. A nil error indicates success.
func NewClient ¶
NewClient creates a new API client with the given options.
If opts is nil, default options are used (see DefaultOptions). The function validates the base URL and returns an error if it's invalid.
Example:
// Create client with default options
client, err := client.NewClient(nil)
// Create client with custom options
client, err := client.NewClient(&client.Options{
BaseURL: "https://api.example.com",
APIKey: "your-api-key",
Timeout: 60 * time.Second,
})
type Options ¶
type Options struct {
// BaseURL is the base URL of the API.
// This should include the protocol (http:// or https://) and host,
// but not the endpoint paths (e.g., "https://api.example.com").
BaseURL string
// APIKey is the API key for authentication.
// If provided, this key will be included in all API requests.
APIKey string
// Timeout is the default request timeout.
// This value is used when no deadline is set in the context.
// If not specified, DefaultTimeout (30 seconds) is used.
Timeout time.Duration
}
Options contains configuration options for the API client. These options control the client's behavior when communicating with the API.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns the default client options. The defaults are: - BaseURL: The value from routes.DefaultBaseURL - APIKey: Empty string (no authentication) - Timeout: DefaultTimeout (30 seconds)
These defaults are suitable for local development but should be customized for production use.