Go SDK
Official Go SDK for SnapSharp. Take screenshots, generate OG images, and run site audits with go get.
Installation
Install the Go SDK using your package manager:
go get github.com/bogdanov-igor/snapsharp-goThen import and initialise the client:
import snapsharp "github.com/bogdanov-igor/snapsharp-go"
snap := snapsharp.New("sk_live_...")Replace sk_live_... with your API key from the dashboard.
Quick Start
Three common use cases to get you up and running in minutes.
1. Take a Screenshot
Capture a screenshot and write the bytes to a file.
package main
import (
"fmt"
"os"
snapsharp "github.com/bogdanov-igor/snapsharp-go"
)
func main() {
snap := snapsharp.New("sk_live_...")
data, err := snap.Screenshot("https://example.com", &snapsharp.ScreenshotParams{
Width: 1280,
Height: 720,
Format: "png",
FullPage: false,
})
if err != nil {
panic(err)
}
os.WriteFile("screenshot.png", data, 0644)
fmt.Println("Screenshot saved!")
}2. Generate an OG Image
Create Open Graph images for social-media previews.
snap := snapsharp.New("sk_live_...")
data, err := snap.OGImage("https://example.com", &snapsharp.OGImageParams{
Template: "default",
Width: 1200,
Height: 630,
})
if err != nil {
log.Fatal(err)
}
os.WriteFile("og-image.png", data, 0644)3. Render HTML to Image
Convert raw HTML and CSS into an image without hosting a page.
snap := snapsharp.New("sk_live_...")
data, err := snap.HTMLToImage("<h1>Hello World</h1>", &snapsharp.HTMLToImageParams{
Width: 800,
Height: 400,
Format: "png",
CSS: "body { font-family: sans-serif; background: #1a1a2e; color: #fff; display: grid; place-items: center; }",
})
if err != nil {
log.Fatal(err)
}
os.WriteFile("html-render.png", data, 0644)API Reference
Complete list of methods available on the Go client.
Screenshot()
Screenshot(url string, params *ScreenshotParams) ([]byte, error)
Captures a screenshot of the given URL. Params include Width, Height, Format, FullPage, Device, DarkMode, Delay, and Headers.
OGImage()
OGImage(url string, params *OGImageParams) ([]byte, error)
Generates an Open Graph image for the URL. Supports Template, Width, and Height params.
HTMLToImage()
HTMLToImage(html string, params *HTMLToImageParams) ([]byte, error)
Renders raw HTML/CSS into an image. Supports Width, Height, Format, CSS, and TransparentBg params.
SiteAudit()
SiteAudit(url string, params *SiteAuditParams) (*AuditResult, error)
Runs a Lighthouse-style performance and SEO audit. Returns an AuditResult struct with scores and diagnostics.
All methods that return images accept an optional format parameter ("png", "jpeg", "webp"). Default is "png". See the full API reference for every available option.
Error Handling
The SDK throws typed errors with HTTP status, message, and a unique request ID for debugging. Always wrap calls in a try/catch to handle rate limits and authentication errors gracefully.
import (
"errors"
"fmt"
snapsharp "github.com/bogdanov-igor/snapsharp-go"
)
data, err := snap.Screenshot("https://example.com", nil)
if err != nil {
var apiErr *snapsharp.APIError
if errors.As(err, &apiErr) {
fmt.Printf("Error %d: %s\n", apiErr.Status, apiErr.Message)
fmt.Printf("Request ID: %s\n", apiErr.RequestID)
if apiErr.Status == 429 {
fmt.Printf("Rate limited. Retry after %ds\n", apiErr.RetryAfter)
}
} else {
fmt.Printf("Unexpected error: %v\n", err)
}
}| Status | Meaning | Action |
|---|---|---|
| 400 | Bad Request — invalid parameters | Check the request body and query params |
| 401 | Unauthorized — invalid or missing API key | Verify your API key in the dashboard |
| 429 | Too Many Requests — rate limit exceeded | Wait for retryAfter seconds |
| 500 | Internal Server Error | Retry with exponential back-off |
Configuration
Customise the client with optional settings passed at initialisation.
import "time"
snap := snapsharp.New("sk_live_...",
snapsharp.WithBaseURL("https://api.snapsharp.dev"), // Custom API base URL
snapsharp.WithTimeout(30 * time.Second), // Request timeout
snapsharp.WithRetries(2), // Auto-retry on 5xx
)| Option | Default | Description |
|---|---|---|
| baseUrl | api.snapsharp.dev | Override the API base URL (e.g. for on-premise) |
| timeout | 30s | Maximum time to wait for a response |
| retries | 0 | Number of automatic retries on 5xx errors |
Ready to start building?
Get your free API key and start capturing screenshots in under a minute. 100 free screenshots every month — no credit card required.