SDK de Go
github.com/serpcheap/serpcheap-go es el cliente oficial de Go — Go 1.21+, solo biblioteca estándar,
consciente del contexto.
Instalación
Sección titulada «Instalación»go get github.com/serpcheap/serpcheap-goInicio rápido
Sección titulada «Inicio rápido»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) }}Opciones
Sección titulada «Opciones»serpcheap.WithBaseURL(string) // override API base URLserpcheap.WithTimeout(time.Duration) // per-request timeoutserpcheap.WithMaxRetries(int) // retries on transient errorsserpcheap.WithHTTPClient(*http.Client) // custom HTTP client