dongqiao0953 2019-08-10 03:36
浏览 88
已采纳

Config for GoLang返回“非名称”错误

I am having trouble compiling code Google-Cloud offers on connecting to a mysql database remotely using Golang.

The code is a direct copy-paste from here: https://cloud.google.com/sql/docs/mysql/connect-external-app#go. One may also look here: https://github.com/GoogleCloudPlatform/cloudsql-proxy/blob/master/proxy/dialers/mysql/hook_test.go.

I've tried providing a second variable to the first line below, but there is an error as only one value is returned by the mysql function.

The troublesome code is on the second line, possibly due to the first line.

cfg := mysql.Cfg("haveibeenexploited:us-west1:hibe", "username", "password")
cfg.DBName := "mythril"
db, err := mysql.DialCfg(cfg)

searchcontract/searchcontract.go:67:5: non-name cfg.DBName on left side of := is the error message I get.

  • 写回答

1条回答 默认 最新

  • dongle3217 2019-08-10 04:51
    关注

    Change this line of code:

    cfg.DBName := "mythril"
    

    to:

    cfg.DBName = "mythril"
    

    The := operator declares a new variable and assigns it a value. This is called "Short Variable Declarations". Since DBName is part of the structure cfg you are using the wrong operator. The correct operator to use is the assignment operator =.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?