3 ms·
Golang newbie here. Using a slice to hold different struct types of the same interface, finding it very annoying that every time I want to access a common attri
by holografix 9y ago
Golang newbie here. Using a slice to hold different struct types of the same interface, finding it very annoying that every time I want to access a common attribute of the struct types I need to define a getter/setter.
- flashmob 9y agoPerhaps you could try creating a struct with just the common properties, then embed the common struct in all your 'extended' structs. Eg. http://www.hydrogen18.com/blog/golang-embedding.html http://www.hydrogen18.com/blog/golang-embedding.html
- holografix 9y agoThat sounds like a bit of a hack. I like it.