Stack Operations¶
The stack operations are implemented in internal/stack/stack.go
.
Stack Structure¶
type Stack struct {
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Assets []Asset `json:"assets"`
}
Available Operations¶
Create Stack¶
func CreateStack(ctx context.Context, client *immich.Client, assets []Asset) (*Stack, error)
Creates a new stack with the given assets.
Parameters:
ctx
: Context for the operationclient
: Immich API clientassets
: Array of assets to include in the stack
Returns:
*Stack
: Created stackerror
: Any error that occurred
Get Stack¶
func GetStack(ctx context.Context, client *immich.Client, stackID string) (*Stack, error)
Retrieves a stack by its ID.
Parameters:
ctx
: Context for the operationclient
: Immich API clientstackID
: ID of the stack to retrieve
Returns:
*Stack
: Retrieved stackerror
: Any error that occurred
Update Stack¶
func UpdateStack(ctx context.Context, client *immich.Client, stack *Stack) error
Updates an existing stack.
Parameters:
ctx
: Context for the operationclient
: Immich API clientstack
: Stack to update
Returns:
error
: Any error that occurred
Delete Stack¶
func DeleteStack(ctx context.Context, client *immich.Client, stackID string) error
Deletes a stack by its ID.
Parameters:
ctx
: Context for the operationclient
: Immich API clientstackID
: ID of the stack to delete
Returns:
error
: Any error that occurred
List Stacks¶
func ListStacks(ctx context.Context, client *immich.Client) ([]Stack, error)
Lists all stacks.
Parameters:
ctx
: Context for the operationclient
: Immich API client
Returns:
[]Stack
: Array of stackserror
: Any error that occurred
Error Handling¶
All operations handle the following error cases:
- Invalid stack ID
- Stack not found
- API errors
- Network errors
- Invalid asset data
Best Practices¶
-
Error Handling
-
Always check returned errors
- Use appropriate error handling strategies
-
Log errors for debugging
-
Context Usage
-
Pass context through all operations
- Use context for cancellation
-
Set appropriate timeouts
-
Asset Management
-
Validate assets before operations
- Handle missing assets gracefully
-
Maintain asset order
-
Stack Naming
- Use descriptive names
- Include relevant metadata
- Follow consistent naming patterns
Example Usage¶
// Create a new stack
stack, err := CreateStack(ctx, client, assets)
if err != nil {
log.Printf("Error creating stack: %v", err)
return
}
// Update stack assets
stack.Assets = append(stack.Assets, newAsset)
err = UpdateStack(ctx, client, stack)
if err != nil {
log.Printf("Error updating stack: %v", err)
return
}
// Delete stack
err = DeleteStack(ctx, client, stack.ID)
if err != nil {
log.Printf("Error deleting stack: %v", err)
return
}