Skip to content
smallPict

Resmi Go SDK

context.Context desteği ve eşzamanlılık güvenliği sunan Go kütüphanesi.

Yüksek verimli mikroservisler için geliştirilmiş, tam eşzamanlılık (concurrency) güvenliğine sahip ve context.Context destekli kütüphane.


Kurulum

Shell
go get github.com/tuxnoob/smallpict-go

Kapsamlı Kullanım Örneği

Go
package main
import (	"context"	"fmt"	"log"	"os"	"time"
	"github.com/tuxnoob/smallpict-go")
func main() {	// 1. İstemciyi başlatın	client, err := smallpict.NewClient(		os.Getenv("SMALLPICT_API_KEY"),		os.Getenv("SMALLPICT_SECRET_KEY"),		smallpict.WithTimeout(15*time.Second),	)	if err != nil {		log.Fatalf("İstemci başlatılamadı: %v", err)	}
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	defer cancel()
	// 2. Yerel dosyayı okuyun	fileBytes, err := os.ReadFile("photo.jpg")	if err != nil {		log.Fatalf("Dosya okunamadı: %v", err)	}
	// 3. Görsel optimizasyonunu çalıştırın	res, err := client.Optimize(ctx, &smallpict.OptimizeRequest{		File:     fileBytes,		Filename: "photo.jpg",		Format:   smallpict.FormatAVIF,		Quality:  80,		MaxWidth: 1920,	})	if err != nil {		log.Fatalf("Optimizasyon sırasında hata: %v", err)	}
	fmt.Printf("Optimize Edilmiş URL: %s\n", res.URL)	fmt.Printf("Elde Edilen Tasarruf: %.2f%%\n", res.SavingsPercentage)}