I am trying to use Google Cloud SQL using go-sql driver. I'm stuck here, I don’t know what is wrong here. This mistake is completely unknown to me.
package hello
import (
"fmt"
"net/http"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
const dbUserName = "userName"
const dbPassword = "password"
const dbIP = "123.123.231.123"
db, err := sql.Open("mysql", dbUserName+":"+dbPassword+"@"+dbIP+":3306/user")
if err != nil {
panic(err.Error())
}
rows, err := db.Query("SELECT * FROM user")
if err != nil {
panic(err.Error())
}
fmt.Println(rows)
defer db.Close()
}
ERROR:
the runtime process gave a bad HTTP response: ''
2015/04/12 09:23:36 http: panic serving 127.0.0.1:50091: Default addr for network '173.194.106.126:3306' unknown
goroutine 6 [running]:
net/http.func·011()
/private/var/folders/00/0v42r000h01000cxqpysvccm003chb/T/appengine/go_appengine/goroot/src/net/http/server.go:1130 +0xbb
main37089.handler(0x5ad1e0, 0xc208044280, 0xc2080331e0)
Any ideas. Looking at the source source of the go-sql driver, maybe I should set the default address?
source
share