> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dragdropdo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go SDK

> The official `dragdropdo-sdk-go` package provides a high‑level interface to the D3 Business API.

## Installation

```bash theme={null}
go get github.com/d3/dragdropdo-sdk-go
```

## Quick start

```go theme={null}
package main

import (
    "fmt"
    "github.com/d3/dragdropdo-sdk-go"
)

func main() {
    // Initialize the client
    client, err := d3.NewDragdropdo(d3.Config{
        APIKey:  "your-api-key-here",
        BaseURL: "https://api.dragdropdo.com", // Optional, defaults to https://api.dragdropdo.com
        Timeout: 30 * time.Second,     // Optional, defaults to 30s
    })
    if err != nil {
        panic(err)
    }

    // Upload a file
    uploadResult, err := client.UploadFile(d3.UploadFileOptions{
        File:     "/path/to/document.pdf",
        FileName: "document.pdf",
        MimeType: "application/pdf",
    })
    if err != nil {
        panic(err)
    }

    fmt.Printf("File key: %s\n", uploadResult.FileKey)
}
```

## Initialization

```go theme={null}
NewDragdropdo(config Config) (*Dragdropdo, error)
```

**Config:**

* `APIKey` (**required**) – your D3 API key.
* `BaseURL` (optional) – API base URL, default: `https://api.dragdropdo.com`.
* `Timeout` (optional) – request timeout, default: `30 * time.Second`.
* `Headers` (optional) – additional headers to send with every request.

## File upload

```go theme={null}
UploadFile(options UploadFileOptions) (*UploadResponse, error)
```

**Options:**

* `File` (**required**) – file path string.
* `FileName` (**required**) – original file name.
* `MimeType` (optional) – MIME type (auto‑detected if omitted).
* `Parts` (optional) – number of upload parts (auto‑calculated).
* `OnProgress` (optional) – progress callback.

Example:

```go theme={null}
result, err := client.UploadFile(d3.UploadFileOptions{
    File:     "/path/to/file.pdf",
    FileName: "document.pdf",
    MimeType: "application/pdf",
    OnProgress: func(progress d3.UploadProgress) {
        fmt.Printf("Upload: %d%%\n", progress.Percentage)
    },
})
```

## Supported operations

```go theme={null}
CheckSupportedOperation(options SupportedOperationOptions) (*SupportedOperationResponse, error)
```

**Options:**

* `Ext` (**required**) – file extension (e.g. `pdf`, `jpg`).
* `Action` (optional) – specific action (`convert`, `compress`, ...).
* `Parameters` (optional) – parameters to validate (e.g. `map[string]interface{}{"convert_to": "png"}`).

Examples:

```go theme={null}
// Get available actions for PDF
actions, _ := client.CheckSupportedOperation(d3.SupportedOperationOptions{
    Ext: "pdf",
})
fmt.Println(actions.AvailableActions)

// Check if convert to PNG is supported
supported, _ := client.CheckSupportedOperation(d3.SupportedOperationOptions{
    Ext:    "pdf",
    Action: "convert",
    Parameters: map[string]interface{}{
        "convert_to": "png",
    },
})
fmt.Printf("Supported: %t\n", supported.Supported)
```

## Create operations

```go theme={null}
CreateOperation(options OperationOptions) (*OperationResponse, error)
```

**Options:**

* `Action` (**required**) – `"convert" | "compress" | "merge" | "zip" | "lock" | "unlock" | "reset_password"`.
* `FileKeys` (**required**) – array of file keys from upload.
* `Parameters` (optional) – action‑specific parameters.
* `Notes` (optional) – user metadata.

Examples:

```go theme={null}
// Convert PDF to PNG
client.CreateOperation(d3.OperationOptions{
    Action:   "convert",
    FileKeys: []string{uploadResult.FileKey},
    Parameters: map[string]interface{}{
        "convert_to": "png",
    },
    Notes: map[string]string{"userId": "user-123"},
})

// Compress
client.CreateOperation(d3.OperationOptions{
    Action:   "compress",
    FileKeys: []string{uploadResult.FileKey},
    Parameters: map[string]interface{}{
        "compression_value": "recommended",
    },
})
```

### Convenience helpers

The client exposes shorthand helpers:

```go theme={null}
client.Convert(fileKeys, convertTo, notes)
client.Compress(fileKeys, compressionValue, notes)
client.Merge(fileKeys, notes)
client.Zip(fileKeys, notes)
client.LockPdf(fileKeys, password, notes)
client.UnlockPdf(fileKeys, password, notes)
client.ResetPdfPassword(fileKeys, oldPassword, newPassword, notes)
```

## Status & polling

```go theme={null}
GetStatus(options StatusOptions) (*StatusResponse, error)
PollStatus(options PollStatusOptions) (*StatusResponse, error)
```

**`StatusOptions`** (used by `GetStatus`):

* `MainTaskID` (**required**) – main task ID from `CreateOperation` / convenience helpers.
* `FileKey` (optional) – when non‑empty, requests status for that specific input file.

**`PollStatusOptions`** (embeds `StatusOptions`; used by `PollStatus`):

* `StatusOptions` – nested struct with `MainTaskID` and `FileKey` as above.
* `Interval` (optional) – `time.Duration` between polls (e.g. `2 * time.Second`); default `2s` if zero.
* `Timeout` (optional) – maximum total polling duration (e.g. `5 * time.Minute`); default `5m` if zero.
* `OnUpdate` (optional) – `func(StatusResponse)`, invoked after each successful status fetch.

Examples:

```go theme={null}
// Single status fetch
status, _ := client.GetStatus(d3.StatusOptions{
    MainTaskID: "task-123",
})

// Poll until completion
finalStatus, _ := client.PollStatus(d3.PollStatusOptions{
    StatusOptions: d3.StatusOptions{
        MainTaskID: "task-123",
    },
    Interval: 2 * time.Second,
    Timeout:  5 * time.Minute,
    OnUpdate: func(status d3.StatusResponse) {
        fmt.Printf("Status: %s\n", status.OperationStatus)
    },
})
```

## Complete workflow example

```go theme={null}
package main

import (
    "fmt"
    "os"
    "time"
    "github.com/d3/dragdropdo-sdk-go"
)

func main() {
    client, err := d3.NewDragdropdo(d3.Config{
        APIKey:  os.Getenv("D3_API_KEY"),
        BaseURL: "https://api.dragdropdo.com",
    })
    if err != nil {
        panic(err)
    }

    // 1. Upload
    uploadResult, err := client.UploadFile(d3.UploadFileOptions{
        File:     "./document.pdf",
        FileName: "document.pdf",
    })
    if err != nil {
        panic(err)
    }

    // 2. Check support
    supported, err := client.CheckSupportedOperation(d3.SupportedOperationOptions{
        Ext:    "pdf",
        Action: "convert",
        Parameters: map[string]interface{}{
            "convert_to": "png",
        },
    })
    if err != nil {
        panic(err)
    }
    if !supported.Supported {
        panic("Convert to PNG is not supported")
    }

    // 3. Create operation
    operation, err := client.Convert(
        []string{uploadResult.FileKey},
        "png",
        map[string]string{"userId": "user-123", "source": "api"},
    )
    if err != nil {
        panic(err)
    }

    // 4. Poll
    status, err := client.PollStatus(d3.PollStatusOptions{
        StatusOptions: d3.StatusOptions{
            MainTaskID: operation.MainTaskID,
        },
        Interval: 2 * time.Second,
    })
    if err != nil {
        panic(err)
    }

    if status.OperationStatus == "completed" {
        for _, file := range status.FilesData {
            fmt.Printf("Download: %s\n", file.DownloadLink)
        }
    }
}
```
