I'm writing my first golang app, so go easy on me!
I have a very simple struct:
type Output struct {
Name string `json:"name"`
}
and I'm also using this golang package to build a CLI app:
I want to assign the value of a cli StringFlag
to the value of the initialized struct. So a boolean flag, I do this:
var testing bool
app.Flags = []cli.Flag{
cli.BoolFlag{Name: "test, T", Usage: "Output to stdout or not", Destination: &testing},
}
This works fine.
However, when I try to initialize the struct, and then assign the value in a similar way, it doesn't work:
struct_values := &Output { }
app.Flags = []cli.Flag{
cli.StringFlag{Name: "name, N", Usage: "The name of the thing", Destination: &struct_values.Name},
}
What am I missing here? I feel like this is relatively straightforward, but my understanding is lacking :(
I was making this way harder than it needed to be :)
I went with:
struct_values := &Output { Name: c.string("name") }
Which got the job done just as easily