Greetings,

I need to be able to assign a value to a struct field where I specify the 
field name in a variable. After searching around I thought the following 
approach would work but I still get the "type does not support indexing" 
error. This example is simplified:

type item struct {
red   bool
green bool
blue  bool
}

func (i *item) setProperty (propName string, propValue bool) *item {
(*i)[propName] = propValue
return i
}

func main() {
item := &item{red: true, green: true}
item = item.setProperty("blue", true)
fmt.Println(item)
}

Is it possible to assign to struct fields where the field name is in a 
variable? Any suggestions on how I get that to work? Thank you.


-- 
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/88a8255a-daa2-43e8-94cc-57851867712fn%40googlegroups.com.

Reply via email to