示例#1
0
func init() {
	RegisterGlobalEvent(GLOBAL_TOPIC, util.JSONCodec(&testType{}))
}
示例#2
0
func init() {
	// GLOBAL_GOOGLE_STORAGE even will be fired with an instance of GoogleStorageEventData
	eventbus.RegisterGlobalEvent(GLOBAL_GOOGLE_STORAGE, util.JSONCodec(&GoogleStorageEventData{}))
}
示例#3
0
// JSONCallback is an adapter between a CallbackFn and a typed function
// that deals with deserialized JSON data.
// Example:
//
//  fn := JSONCallback(&MyType{}, func(data interface{}, err error) {
//     ... data.(*MyType)
//  })
//  fn(jsonBytes)
//
// This assumes that jsonBytes is valid JSON to deserialize to an
// instance of MyType.
//
func JSONCallback(instance interface{}, callback func(data interface{}, err error)) CallbackFn {
	codec := util.JSONCodec(instance)
	return func(byteData []byte) {
		callback(codec.Decode(byteData))
	}
}