Skip to content

Instantly share code, notes, and snippets.

@NaotoKumagai
Last active October 10, 2016 21:18
Show Gist options
  • Save NaotoKumagai/7d247b4d8fe86f41d9d0363130786b0e to your computer and use it in GitHub Desktop.
Save NaotoKumagai/7d247b4d8fe86f41d9d0363130786b0e to your computer and use it in GitHub Desktop.
GoogleCustomSearchを適当に叩く(エラーガン無視...)
package main
import (
"fmt"
"github.com/franela/goreq"
)
type Parameter struct {
Key string
Q string
Cx string
Num uint8
SearchType string `url:"searchType"` //全て小文字に変換されてしまうので、明示的にキー名を指定
}
func main() {
url := "https://www.googleapis.com/customsearch/v1/"
param := Parameter {
Key: "【APIキー】",
Cx: "【検索エンジンID】",
Q: "google", // 検索ワード
SearchType: "image", // 今回は画像検索
Num: 3, // 検索結果の数
}
fmt.Printf(search(url,param))
}
func search(url string,query interface{}) (string) {
res, _ := goreq.Request{
Uri: url,
QueryString: query,
ShowDebug: true,
}.Do()
str, _ := res.Body.ToString()
return str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment