Skip to content

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 operation
  • client: Immich API client
  • assets: Array of assets to include in the stack

Returns:

  • *Stack: Created stack
  • error: 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 operation
  • client: Immich API client
  • stackID: ID of the stack to retrieve

Returns:

  • *Stack: Retrieved stack
  • error: 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 operation
  • client: Immich API client
  • stack: 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 operation
  • client: Immich API client
  • stackID: 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 operation
  • client: Immich API client

Returns:

  • []Stack: Array of stacks
  • error: 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

  1. Error Handling

  2. Always check returned errors

  3. Use appropriate error handling strategies
  4. Log errors for debugging

  5. Context Usage

  6. Pass context through all operations

  7. Use context for cancellation
  8. Set appropriate timeouts

  9. Asset Management

  10. Validate assets before operations

  11. Handle missing assets gracefully
  12. Maintain asset order

  13. Stack Naming

  14. Use descriptive names
  15. Include relevant metadata
  16. 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
}