【问题标题】:Server Error 500 when deploying Go backend with Gorm, using CloudSQL and Google App Engine使用 CloudSQL 和 Google App Engine 使用 Gorm 部署 Go 后端时出现服务器错误 500
【发布时间】:2020-09-26 20:01:00
【问题描述】:

我正在尝试在 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'

任何帮助将不胜感激:)

【问题讨论】:

  • 你有使用环境变量CLOUDSQL_CONNECTION_NAME的代码吗?

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


【解决方案1】:

我确实没有使用正确的 ENV 变量。感谢您指出@Muffin Top

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 2016-10-27
    • 2017-12-28
    • 2013-08-30
    相关资源
    最近更新 更多