I was trying to define a new struct type with an anonymous map field.
Something like this:
type myMap map[string]string
type myStruct struct {
myMap
}
As expected I can create a map of type myMap and give values:
r := make(myMap)
r["hola"] = "adios"
fmt.Println(r)
// Prints: map[hola:adios]
However, I tried creating a new variable of type myStruct and give values
in the same fashion but doesn't work:
r := &myStruct{make(myMap)}
r["hola"] = "adios"
fmt.Println(r)
// Prints: invalid operation: r["hola"] (index of type *myStruct)
I was wondering if there is any way to set/get data from the anonymous map
using the [] syntax. Obviously I could not use an anonymous map and just
refer to the attribute (or creating some setters/getters), but I think it
would be cleaner if I could just do it this way.
Thanks!
Cristobal
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.