goSocket
A socket server which achieve following function by native Go http package:
-
A custom communication protocol between server and client;
-
A custom connecting mechanism of heartbeating;
-
Read operational parameters from config files;
-
A router-controller structure to decouple codes of server.
You can see all the details in my chinese blog
goSocket
一个通过Go语言原生包实现了如下功能的socket server:
-
自定义通讯协议
-
通过心跳机制维护连接
-
从配置文件中读取系统参数
-
通过 router-controller 机制解耦服务器
详情可参加我的中文blog (出国后因为更换手机号的原因,之前的blog账号无法验证登陆了,所以没法更新文章里的一些小错误和回复评论,有疑问的可以在issue里提问)
##Example:
//modify a controller in /utils/router.go
type EchoController struct {
}
//create a new controller
func (this *EchoController) Excute(message Msg)[]byte {
mirrormsg,err :=json.Marshal(message)
Log("echo the message:", string(mirrormsg))
CheckError(err)
return mirrormsg
}
//register this controller
func init() {
var echo EchoController
routers = make([][2]interface{} ,0 , 20)
Route(func(entry Msg)bool{
if entry.Meta["meta"]=="test"{
return true}
return false
},&echo)
}
//after setting parameters in config.yaml, run server.go
func main() {
startServer("./conf/config.yaml")
}