Go (Golang) SDK
고성능 마이크로서비스를 위해 최적화된 공식 smallpict-go 라이브러리.
공식 SmallPict Go SDK는 제로 메모리 할당 HMAC 서명 연산과 Context 기반의 안전한 HTTP 통신을 지원합니다.
패키지 설치
Shell
go get github.com/tuxnoob/smallpict-go빠른 시작 예제
Go
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. 이미지 바이트 슬라이스 최적화 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("최적화된 URL: %s (절감률: %.2f%%)\n", result.URL, result.SavingsPercentage)
// 2. 계정 쿼터 상태 조회 quota, err := client.GetQuota(ctx) if err == nil { fmt.Printf("플랜: %s, 사용량: %d / %d 바이트\n", quota.Plan, quota.BytesUsed, quota.QuotaLimitBytes) }}