2,348
社区成员




package msg
import (
"github.com/name5566/leaf/network"
)
var Processor network.Processor
func init() {
Processor.Register(&Hello{})
}
// 一个结构体定义了一个 JSON 消息的格式
// 消息名为 Hello
type Hello struct {
Name string
}
package network
type Processor interface {
// must goroutine safe
Route(msg interface{}, userData interface{}) error
// must goroutine safe
Unmarshal(data []byte) (interface{}, error)
// must goroutine safe
Marshal(msg interface{}) ([][]byte, error)
}