Language

Go Screenshot API

High-performance screenshot capture with Go using the standard net/http package. Build fast, concurrent screenshot services with goroutines and channels. Includes examples for parallel batch capture, context-based timeouts, streaming responses to disk, and deploying as a microservice.

Quick Start

1

Install dependencies

No external dependencies needed — Go's standard library net/http handles all HTTP requests.

2

Get your API key

Sign up for Screenshotly and get your API key from the dashboard.

3

Copy the code example

Use our Go code example as a starting point.

4

Customize and integrate

Modify the code to fit your specific use case and requirements.

Code Example

// Go
package main

import (
    "bytes"
    "encoding/json"
    "io"
    "net/http"
    "os"
)

func captureScreenshot(url, outputPath string) error {
    payload, _ := json.Marshal(map[string]interface{}{
        "url":    url,
        "device": "desktop",
        "format": "png",
    })

    req, _ := http.NewRequest("POST", 
        "https://api.screenshotly.app/screenshot", 
        bytes.NewBuffer(payload))
    
    req.Header.Set("Authorization", "Bearer "+os.Getenv("SCREENSHOTLY_API_KEY"))
    req.Header.Set("Content-Type", "application/json")
    
    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        return err
    }
    defer resp.Body.Close()
    
    data, _ := io.ReadAll(resp.Body)
    return os.WriteFile(outputPath, data, 0644)
}

When to Use Go with Screenshotly

Use the Go integration for high-throughput microservices, CLI tools, and concurrent screenshot pipelines. Go excels at processing thousands of captures per minute with minimal memory overhead thanks to goroutines and efficient streaming I/O.

Go Best Practices

Use a semaphore pattern (buffered channel of size N) to limit concurrent goroutines to your plan's rate limit.

Always pass context.WithTimeout to http.NewRequestWithContext — this prevents goroutine leaks on slow or hung API responses.

Use io.Copy(file, resp.Body) to stream directly to disk instead of io.ReadAll, especially for full-page screenshots.

Build a reusable http.Client with custom Transport settings: MaxIdleConnsPerHost=10, IdleConnTimeout=90s for connection pooling.

Want a step-by-step walkthrough?

Read the full Go tutorial →

API Reference

EndpointPOST /api/screenshot
AuthenticationBearer token
Content-Typeapplication/json
View full API docs

Frequently Asked Questions

How do I capture screenshots concurrently in Go?

Use goroutines with a semaphore pattern (buffered channel) to limit concurrent requests. This prevents hitting rate limits while maximizing throughput. A worker pool of 5-10 concurrent captures is a good starting point.

What's the best way to handle errors in Go?

Check resp.StatusCode after each request. Implement retry logic with exponential backoff for 429 and 5xx errors. Use context.WithTimeout to prevent hung requests. Return errors up the call chain rather than logging and continuing.

Can I use Screenshotly in a Go microservice?

Yes. Create a screenshot service with an HTTP handler that accepts URL parameters and returns captured images. Use Go's standard http package or frameworks like Gin/Echo. Store API keys in environment variables.

How do I stream screenshot responses in Go?

Use io.Copy to stream the API response body directly to your HTTP response writer or file, avoiding loading the entire image into memory. This is especially important for full-page screenshots that can be several megabytes.

Start building with Go

Get your API key and start capturing screenshots in minutes.

Other Languages