Go SDK
CaptchaSonic 공식 Go SDK — gRPC 바이너리 + HTTP/REST 전송, 함수형 옵션, 컨텍스트 인식.
CaptchaSonic CAPTCHA solving API용 공식 Go SDK입니다 — gRPC 바이너리 전송(가장 빠름) + HTTP/REST 폴백을 지원합니다.
설치
go get github.com/Captcha-Sonic/captchasonic-go@latest
특정 버전으로 고정하려면:
go get github.com/Captcha-Sonic/[email protected]
빠른 시작
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/Captcha-Sonic/captchasonic-go"
)
func main() {
// Create client — gRPC binary transport (default, fastest)
client, err := captchasonic.NewClient("sonic_your_api_key")
if err != nil {
log.Fatal(err)
}
defer client.Close()
ctx := context.Background()
// Check balance
balance, _ := client.GetBalance(ctx)
fmt.Printf("Balance: $%.4f\n", balance)
// Solve CAPTCHA — images sent as raw binary (zero base64 overhead)
imgBytes, _ := os.ReadFile("tile.png")
resp, err := client.SolvePopularCaptcha(ctx, [][]byte{imgBytes},
"Select all traffic lights", "objectClassify")
if err != nil {
log.Fatal(err)
}
fmt.Println("Solution:", resp.TypedSolution.GetGrid().GetObjects())
}
전송 방식
| 전송 방식 | 기본값 | 속도 | 이미지 |
|---|---|---|---|
| gRPC | ✅ 예 | 가장 빠름 — 바이너리, HTTP/2 | 원시 []byte |
| HTTP | 아니요 | 양호 — JSON REST | 자동 base64 인코딩 |
gRPC가 기본값입니다. REST 전송이 꼭 필요한 경우에만
WithHTTP()를 전달하세요.
설정 옵션
// Production gRPC (default)
client, _ := captchasonic.NewClient("sonic_xxxx")
// HTTP/REST transport
client, _ := captchasonic.NewClient("sonic_xxxx", captchasonic.WithHTTP())
// Custom endpoint
client, _ := captchasonic.NewClient("sonic_xxxx",
captchasonic.WithEndpoint("api.captchasonic.com:443"))
// Local development (insecure gRPC)
client, _ := captchasonic.NewClient("sonic_xxxx",
captchasonic.WithEndpoint("localhost:50052"),
captchasonic.WithInsecure())
// Advanced options
captchasonic.WithTimeout(45 * time.Second)
captchasonic.WithGRPCMsgSize(100 * 1024 * 1024) // 100 MB max message
captchasonic.WithHTTPPool(200, 200, 90*time.Second)
솔브 메서드
PopularCaptcha
resp, err := client.SolvePopularCaptcha(ctx, images,
"Select all traffic lights", "objectClassify",
captchasonic.WithWebsite("https://example.com", "sitekey"))
ReCaptcha V2
resp, err := client.SolveRecaptchaV2(ctx, images, "traffic lights",
captchasonic.WithQuestionType("split_33"),
captchasonic.WithWebsiteURL("https://example.com"))
OCR (이미지-텍스트 변환)
// MtCaptcha
resp, err := client.SolveOcr(ctx, images,
captchasonic.WithModule("mtcaptcha"),
captchasonic.WithLengthRange(4, 6))
// BLS (numeric)
resp, err := client.SolveOcr(ctx, images,
captchasonic.WithModule("bls"),
captchasonic.WithNumeric())
Geetest
// Nine-grid
resp, err := client.SolveGeetest(ctx, "nine", "the bear",
captchasonic.WithImages(tiles))
// Slide
resp, err := client.SolveGeetest(ctx, "slide", "",
captchasonic.WithImages(puzzle),
captchasonic.WithExamples(piece))
// Click
resp, err := client.SolveGeetest(ctx, "click", "the bear",
captchasonic.WithImages(tiles))
TikTok (유형 기반)
resp, err := client.SolveTikTok(ctx, "whirl", "Rotate to match", images,
captchasonic.WithExamples(examples))
resp, err := client.SolveTikTok(ctx, "click", "Select shape", images)
resp, err := client.SolveTikTok(ctx, "slide", "", images)
Binance (유형 기반)
resp, err := client.SolveBinance(ctx, "grid", "Select the bicycle", images)
resp, err := client.SolveBinance(ctx, "slide", "", images)
AWS WAF
resp, err := client.SolveAwsWaf(ctx, images, "Select all squares",
captchasonic.WithWebsiteURL("https://example.com"))
Turnstile (토큰 작업 — 자동 폴링)
resp, err := client.SolveTurnstile(ctx, "https://example.com", "0x4AAAAAAA")
기타 토큰 작업
// Cloudflare (proxy REQUIRED)
client.SolveCloudflare(ctx, url, key, "http://user:pass@host:1080")
// reCAPTCHA v2/v3 token
client.SolveRecaptchaV2Token(ctx, url, key, captchasonic.WithProxyless())
client.SolveRecaptchaV3Token(ctx, url, key, captchasonic.WithProxy("..."))
// PopularCaptcha token (PopularCaptcha browser automation)
client.SolvePopularCaptchaToken(ctx, url, key, captchasonic.WithProxyless())
작업 옵션 헬퍼
captchasonic.WithImages(imgs) // set images via option
captchasonic.WithExamples(exampleImages) // reference images
captchasonic.WithScreenshot() // enable screenshot
captchasonic.WithWebsite(url, key) // billing: websiteUrl + websiteKey
captchasonic.WithWebsiteURL(url) // billing: websiteUrl only
captchasonic.WithQuestionType(qt) // e.g. "objectDrag", "split_33"
captchasonic.WithProxy("http://...") // proxy for token tasks
captchasonic.WithProxyless() // proxyless variant
captchasonic.WithModule("bls") // OCR module
captchasonic.WithNumeric() // OCR: digits only
captchasonic.WithCaseSensitive() // OCR: case sensitive
captchasonic.WithLengthRange(3, 8) // OCR: min/max text length
captchasonic.WithGeetestVersion(4) // Geetest version
오류 처리
resp, err := client.GetBalance(ctx)
if err != nil {
if sonicErr, ok := err.(*captchasonic.SonicError); ok {
fmt.Printf("API error %d: %s\n", sonicErr.ErrorID, sonicErr.Message)
}
}
UNAVAILABLE, RESOURCE_EXHAUSTED, DEADLINE_EXCEEDED가 발생하면 지수 백오프(1초, 2초)로 자동 재시도합니다.
검증
NewClient는 API 키 형식을 즉시 검증하며, 네트워크 호출은 하지 않습니다:
"sonic_"로 시작해야 합니다- 최소 12자 이상이어야 합니다
작업별 검증: 이미지 필수 여부/개수/크기, 질문 필수 여부, 프록시 형식.
커넥션 풀링
- gRPC: 단일
grpc.ClientConn이 모든 호출을 HTTP/2 스트림으로 다중화합니다. 10초마다 keep-alive 핑을 보냅니다. 한 번 생성한 뒤 고루틴 간에 재사용하세요. - HTTP: 구성 가능한
MaxConnsPerHost(기본값 100)를 가진http.Transport를 사용합니다.