There is another improvement you can do: you are currently using cfg := Config{Name: &nameField} r := reflect.ValueOf(cfg)
which means that 'r' will contain a copy of 'cfg' and will not be settable. If instead you use: r := reflect.ValueOf(&cfg).Elem() then r will contain a *pointer* to the original 'cfg' and can modify it (the reflect.Value 'r' is settable). In turn, this also allows to declare 'Config' as follows: ``` type Config struct { Name String } ``` i.e. removes the need to use a *pointer* to String. You also need some minor adjustments to the rest of the code... A complete example is: https://play.golang.org/p/AxPE0K_ivxP On Wednesday, May 29, 2019 at 11:56:42 AM UTC+2, Sotirios Mantziaris wrote: > > Ok, found it. I should have used the reflect.ValueOf... > > On Wednesday, May 29, 2019 at 12:53:13 PM UTC+3, Sotirios Mantziaris wrote: >> >> I did found out that the setter method has to accept a pointer to string. >> I have a complete example now which unfortunately don't work correclty. >> The value should change but it is emptied out. >> >> https://play.golang.org/p/OPZKltApEhF >> >> What am i missing? >> >> On Wednesday, May 29, 2019 at 10:46:32 AM UTC+3, Jan Mercl wrote: >>> >>> On Wed, May 29, 2019 at 9:42 AM Sotirios Mantziaris >>> <smant...@gmail.com> wrote: >>> >>> > I am getting the nested "Name" struct but there are no methods to >>> call. >>> > What am i doing wrong (besides using reflection :))? >>> >>> The method has a pointer receiver: https://play.golang.org/p/qjhqSvhE9PL >>> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b7ac54f5-515c-448d-84db-f58ee7e80697%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.