LoginSignup
0
0

More than 5 years have passed since last update.

GAE/GoからalgoliaのAPIを叩いても結果が返ってこない件の対処

Last updated at Posted at 2018-10-19

GAE/Goからalgoliaを利用する時、httpClientを置き換えないと失敗する様子。appengine用にtransportを設定し直す必要があるみたいです。

import (
    "context"
    "github.com/algolia/algoliasearch-client-go/algoliasearch"
    "google.golang.org/appengine/urlfetch"
    "net/http"
)

ctx := appengine.NewContext(r)
client := algoliasearch.NewClient(APP_ID, ADMIN_KEY)

// 下のコードを書く必要がある
transport := &http.Client{
    Transport: &urlfetch.Transport{
        AllowInvalidServerCertificate: true,
        Context: ctx,
    },
}
client.SetHTTPClient(transport)

ローカルでは動いてて、本番環境だと動かない時はこれが原因っぽいです。恐らくalgolia以外で外部APIを叩くライブラリでも同じ設定が必要になりそう

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0