Help us understand the problem. What is going on with this article?

Go+GAE+外部MySQLで躓いたはなし

More than 1 year has passed since last update.

GAE上でGOを動かして、そこから外部のMySQLに接続するのに躓いたのでメモをしておきます。
どうやら、GAEからはSocketAPIなるものを使わないと外部には接続できないようです。
ローカルで動作しましたが、GAEにアップするとヌルポがでるので、最初はわかりませんでした。
解決コードはあっさりしてます。
importは省いています。

サンプル

sample.go(抜粋)
dsn :=  con.User + ":" + con.Password + "@external(" + con.Address + ":" + strconv.Itoa(con.Port) + ")/" + con.Name
dial := func(addr string) (net.Conn, error) {
  return socket.Dial(appengine.NewContext(r), "tcp", addr)
}
mysql.RegisterDial("external", dial)
db, err := sql.Open("mysql",dsn)

externalという名前のDialを作成し、mysqlに登録するだけです。
DSNではいつもは、@tcpとなるところが登録名@externalになるだけです。

Go+GAEではvendor関係とかつまづきまくっていますが、総じてGo言語の生産性と実行速度は十分に満足がいくものです。

追加

Go1.11でなんとかなるかもしれないので、今度試してみます
https://github.com/gcpug/nouhau/tree/feature/id/76/app-engine/note/gaego19-migration-gaego111

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away