コンテンツにスキップ

Go SDK

github.com/serpcheap/serpcheap-go は公式の Go クライアントです — Go 1.21+、標準ライブラリのみ、 コンテキスト対応。

Terminal window
go get github.com/serpcheap/serpcheap-go
package main
import (
"context"
"fmt"
"log"
"time"
serpcheap "github.com/serpcheap/serpcheap-go"
)
func main() {
client, err := serpcheap.New("YOUR_API_KEY",
serpcheap.WithTimeout(15*time.Second),
serpcheap.WithMaxRetries(2),
)
if err != nil {
log.Fatal(err)
}
res, err := client.Search(context.Background(), serpcheap.SearchParams{
Q: "best running shoes", GL: "us", Page: 1,
})
if err != nil {
if e, ok := serpcheap.AsError(err); ok {
log.Fatalf("[%s] %s (retryable=%v)", e.Code, e.Message, e.Retryable())
}
log.Fatal(err)
}
for _, r := range res.Organic {
fmt.Printf("%d. %s — %s\n", r.Position, r.Title, r.Link)
}
}
serpcheap.WithBaseURL(string) // override API base URL
serpcheap.WithTimeout(time.Duration) // per-request timeout
serpcheap.WithMaxRetries(int) // retries on transient errors
serpcheap.WithHTTPClient(*http.Client) // custom HTTP client