I assume you are accessing a value like this
package main import "fmt" import "github.com/codegangsta/cli" func main() { fmt.Println("Hello, playground") a := Something() fmt.Printf("%T \n", a[0].Name) } func Something() []cli.Flag { return []cli.Flag{ cli.StringFlag{ Name: "awesome", Usage: "be awesome", }, cli.StringFlag{ Name: "awesome2", }, } }
Which will give you the following error:
./main.go:10: a[0].Name undefined (type cli.Flag has no field or method Name)
And the problem with this code is that you are accessing the values โโof struct cli.StringFlag through the cli.Flag interface. You need to introduce the conversion of this interface to the actual structure type.
We hope that the following code will make a difference.
package main import "fmt" import "github.com/codegangsta/cli" func main() { a := Something() stringFlag, ok := a[0].(cli.StringFlag) if ok { fmt.Println(stringFlag.Name) } } func Something() []cli.Flag { return []cli.Flag{ cli.StringFlag{ Name: "awesome", Usage: "be awesome", }, cli.StringFlag{ Name: "awesome2", }, } }
source share