go - 使用CloudSQL和Google App Engine在Gorm上部署Go后端时出现服务器错误500

标签 go google-app-engine google-cloud-sql go-gorm

我正在尝试在Google App Engine上部署Go后端,并连接到CloudSQL。部署魔术有效,但是当我尝试调用API时,状态为500:

Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.

当运行gcloud app logs tail -s default时,我有:
2020/06/07 21:39:26 server.go:52: dial unix /cloudsql/: connect: is a directory
    var dbURI string
    dbURI = fmt.Sprintf("%s:%s@unix(/cloudsql/%s)/%s", dbUser, dbPwd, dbHost, dbName)

    // Open database connection
    db, err := gorm.Open(
        "mysql",
        dbURI,
    )
    if err != nil {
        log.Fatal(err) <-- line 52
    }

我的app.yaml设置正确(我认为..):
env_variables:
  CLOUDSQL_CONNECTION_NAME: 'XXXXX:europe-west1:XXXXXX'
  DB_USER: 'root'
  DB_PASS: 'XXXXX'
  DB_NAME: 'XXXXX'

任何帮助,将不胜感激 :)

最佳答案

我确实没有使用正确的ENV变量。谢谢您指出@Muffin返回页首

关于go - 使用CloudSQL和Google App Engine在Gorm上部署Go后端时出现服务器错误500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62252167/

相关文章:

go - bytes.Split()如何处理从UTF-8字符串转换的字节?

reactjs - 我如何在同一个域上运行 Golan 应用程序(后端)和 ReactJS 应用程序(前端)以防止 CORS?

regex - app.yaml skip_files 跳过整个目录,但跳过一个单独的文件

java - Google App Engine 后端实例是否适合我的应用程序?

google-cloud-sql - 从容器引擎连接到 Google Cloud SQL : can't resolve cloud sql proxy

go - 如何在 Golang 中使用 HTTP/2 写入/读取/发送数据帧?

php - PHP 和 Go 中的 hmac 哈希不匹配

java - GAE 资源文件 FileNotFoundException

mysql - Google Cloud SQL Mysql 组复制

mysql - 无法使用客户端 mysql CL 工具连接到 Google Cloud SQL 实例