go - value returned by flags into my struct
问题描述
How can I assign the string value returned by flag into my struct? I have the following code.
destDbCfg = &dbhelper.DbConfig {}
destDbCfg.Database = flag.String( "destDBName", "", "Destination DB Database Name")
flag.Parse()
Database is a string
解决方案
使用这些*Var
方法将设置值设置为标志中的现有变量,在这种情况下,您需要flag.StringVar
destDbCfg = &dbhelper.DbConfig{}
flag.StringVar(&destDbCfg.Database, "destDBName", "", "Destination DB Database Name")
flag.Parse()
推荐阅读
- python - 如何绘制多模型的计算时间?
- python - 从图像中去除“噪声”或“孔洞”
- react-native - 管理依赖于道具的样式的最佳方法是什么?
- javascript - 数据表自定义过滤器可在单击按钮时删除具有重复数据的行
- c# - 将 .net Framework 4.5 MVC 应用程序重定向到 /authorize Microsoft Oauth 2.0 端点以检索授权代码
- android - 当运行 ionic cordova run android 时,命令提示符上显示 tranformclasses 错误
- django - 将生产 Django 服务器 + Postgres 数据库复制到相同的 Linode 服务器作为备份
- arrays - 使用 .each 将数组转换为哈希数组
- python - Python从循环中的数据框创建字典
- javascript - 获取javascript中选定选项的值