Go (Golang) SDK

Official smallpict-go library for high-throughput Go microservices.

Go SDK (smallpict-go)

The official SmallPict Go SDK delivers idiomatic, zero-allocation cryptographic HMAC request signing and context-aware HTTP execution.


📦 Installation

go get github.com/tuxnoob/smallpict-go

🚀 Quickstart Example

package main

import (
	"context"
	"fmt"
	"os"
	"time"

	smallpict "github.com/tuxnoob/smallpict-go"
)

func main() {
	client := smallpict.NewClient(
		os.Getenv("SMALLPICT_API_KEY"),
		os.Getenv("SMALLPICT_SECRET_KEY"),
		smallpict.WithTimeout(30*time.Second),
		smallpict.WithMaxRetries(3),
	)

	ctx := context.Background()

	// 1. Optimize image bytes
	fileBytes, err := os.ReadFile("hero.png")
	if err != nil {
		panic(err)
	}

	result, err := client.Optimize(ctx, fileBytes, smallpict.OptimizeOptions{
		Format:   "avif",
		Quality:  85,
		MaxWidth: 1920,
	})
	if err != nil {
		panic(err)
	}

	fmt.Printf("Optimized URL: %s (Saved %.2f%%)\n", result.URL, result.SavingsPercentage)

	// 2. Fetch account quota
	quota, err := client.GetQuota(ctx)
	if err == nil {
		fmt.Printf("Plan: %s, Quota Used: %d / %d bytes\n", quota.Plan, quota.BytesUsed, quota.QuotaLimitBytes)
	}
}