← 블로그로 돌아가기

Go로 Google Search API 사용하기: 완전 튜토리얼 (2026)

Go(Golang)에서 Google Search API 사용하기 — net/http 요청, 구조체로 JSON 디코딩, 재시도와 페이지네이션. serp.cheap으로 복사-붙여넣기 예제.

1 분 소요

표준 라이브러리만으로 Go에서 Google에 쿼리하세요. serp.cheap을 사용합니다 — 또는 공식 Go SDK(go get github.com/serpcheap/serpcheap-go)를 사용해도 됩니다. 어느 쪽이든 단순한 HTTP+JSON 엔드포인트입니다.

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)
}

프로덕션에서는 429/5xx에 대한 지수 백오프 재시도와 context.Context 타임아웃을 추가하세요.

다음

Frequently asked questions

Go에서 Google Search API를 어떻게 호출하나요?+

net/http를 사용해 SERP API에 JSON 본문을 POST하고 응답을 구조체로 디코딩하세요. serp.cheap에서는 엔드포인트가 https://api.serp.cheap/v1/search 이며 X-API-Key 헤더를 사용합니다.

서드파티 Go SDK가 필요한가요?+

아니요 — 표준 라이브러리의 net/http와 encoding/json만으로 충분합니다. SERP API는 단순한 HTTP+JSON 엔드포인트입니다.

API 키 받기

직접 구매가 가장 저렴, 카드 또는 암호화폐로 결제, KYC 불필요. 또는 마켓플레이스 이용.