I do know there's no way to use var rule = map[uint8]Message{ 0: thisType, 1: thatType, 4: someOtherType, ..... }
type Message interface { .... Become(data []byte) .... } type thisType struct { data []byte } func (my *thisType) Become(data []byte) { ....} type thatType struct { data []byte } func (my *thatType) Become(data []byte) { ....} WHAT I'M TRYING TO DO IS: I receive a data packet via UDP, it has an Id byte, a payload and ends with a crc32. |id|....payload....|crc32 Upon reception I need to encapsulate the payload into a struct, and choose the right type of struct depending on the value of the ID byte. Different kinds of payloads get managed by different types of structs, the interface ensure all needed structs implement a common API. I wonder if there's a way to do what I'm trying to do without using a switch. Anything as declarative as a map would make things a lot easier for anyone who isn't familiar with the code. However, I see no way to use a map for this. Thanks in advance Berto -- 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/48c7bcaf-8836-44ce-9ccc-df2c53c90365n%40googlegroups.com.