value returned by flags into my struct

1.4k Views Asked by At

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

1

There are 1 best solutions below

1
JimB On

Use the *Var methods to set set values to existing variables from flags, in this case you want flag.StringVar

destDbCfg = &dbhelper.DbConfig{}

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