使用通道在Go中进行事件处理

I have written an SDK that encapsulates a bunch of logic and functionality.

Typically, I would use event listeners/callbacks to provide feedback to the application using the SDK, but that is not idiomatic in Go.

It is my understanding that channels and goroutines fill the void of callbacks but what is a way to implement this?

Say for example, my SDK has a number of events that I want to notify the main application about. Would I use one channel based on an Event struct. This Event would contain a _type field which specifies the event type, then a data field of type interface{} similar to Object in Java. The receiver would then check the type and cast the data accordingly.

Either the above approach or one channel for event then the app listens for whatever channels it is concerned with.

For the record I prefer the former approach but unsure about it's implementation.

Has anybody achieve this before and how did you implement?

Take a look at my https://github.com/tideland/gocells. It's a library for event driven applications. Here so called cells are started with behaviors responsible to process the events, these cells are connected.

Maybe you can use it or get some inspiration.