← Zurück zum Blog

Google Search API in Go: Komplettes Tutorial (2026)

Eine Google Search API in Go (Golang) nutzen — net/http-Anfragen, JSON in Structs dekodieren, Retries und Paginierung. Copy-Paste-Beispiele mit serp.cheap.

1 Min. Lesezeit

Frage Google aus Go ab — allein mit der Standardbibliothek, mithilfe von serp.cheap — oder binde das offizielle Go-SDK ein (go get github.com/serpcheap/serpcheap-go). So oder so ist es ein simpler HTTP+JSON-Endpunkt.

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
)

type Result struct {
	Position int    `json:"position"`
	Title    string `json:"title"`
	Link     string `json:"link"`
	Snippet  string `json:"snippet"`
}

type Response struct {
	Organic []Result `json:"organic"`
	Stats   struct {
		Balance int  `json:"balance"`
		Cost    int  `json:"cost"`
		Cached  bool `json:"cached"`
	} `json:"stats"`
}

func search(apiKey, q, gl string, page int) (*Response, error) {
	body, _ := json.Marshal(map[string]any{"q": q, "gl": gl, "page": page})
	req, _ := http.NewRequest("POST", "https://api.serp.cheap/v1/search", bytes.NewReader(body))
	req.Header.Set("X-API-Key", apiKey)
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("search failed: HTTP %d", resp.StatusCode)
	}
	var out Response
	if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
		return nil, err
	}
	return &out, nil
}

func main() {
	res, err := search("YOUR_KEY", "best electric cars 2026", "us", 1)
	if err != nil {
		panic(err)
	}
	for _, r := range res.Organic {
		fmt.Printf("#%d %s — %s\n", r.Position, r.Title, r.Link)
	}
	fmt.Printf("cost: %d credits, cached: %v\n", res.Stats.Cost, res.Stats.Cached)
}

Für den Produktivbetrieb füge einen Retry bei 429/5xx mit exponentiellem Backoff und einen context.Context-Timeout hinzu.

Weiter

Häufige Fragen

Wie rufe ich eine Google Search API in Go auf?+

Nutze net/http, um einen JSON-Body an die SERP API zu senden, und dekodiere die Antwort in ein Struct. Bei serp.cheap ist der Endpunkt https://api.serp.cheap/v1/search mit einem X-API-Key-Header.

Brauche ich ein Drittanbieter-Go-SDK?+

Nein — net/http und encoding/json aus der Standardbibliothek reichen aus. Eine SERP API ist ein simpler HTTP+JSON-Endpunkt.

Hol dir deinen API-Key

Am günstigsten direkt, mit Karte oder Krypto zahlen, kein KYC. Oder über einen Marktplatz.