首页 > 解决方案 > 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

标签: gogo-flag

解决方案


使用这些*Var方法将设置值设置为标志中的现有变量,在这种情况下,您需要flag.StringVar

destDbCfg = &dbhelper.DbConfig{}

flag.StringVar(&destDbCfg.Database, "destDBName", "", "Destination DB Database Name")
flag.Parse()

推荐阅读