Ai
2 Star 0 Fork 0

MixerJ/pitaya

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
MixerJ 提交于 2020-07-18 16:58 +08:00 . !1go mod
package main
import (
"flag"
"fmt"
"strings"
"gitee.com/mixerj/pitaya"
"gitee.com/mixerj/pitaya/acceptor"
"gitee.com/mixerj/pitaya/component"
"gitee.com/mixerj/pitaya/examples/demo/cluster_protobuf/services"
"gitee.com/mixerj/pitaya/serialize/protobuf"
)
func configureBackend() {
room := services.NewRoom()
pitaya.Register(room,
component.WithName("room"),
component.WithNameFunc(strings.ToLower),
)
pitaya.RegisterRemote(room,
component.WithName("room"),
component.WithNameFunc(strings.ToLower),
)
}
func configureFrontend(port int) {
ws := acceptor.NewWSAcceptor(fmt.Sprintf(":%d", port))
pitaya.Register(&services.Connector{},
component.WithName("connector"),
component.WithNameFunc(strings.ToLower),
)
pitaya.RegisterRemote(&services.ConnectorRemote{},
component.WithName("connectorremote"),
component.WithNameFunc(strings.ToLower),
)
pitaya.AddAcceptor(ws)
}
func main() {
port := flag.Int("port", 3250, "the port to listen")
svType := flag.String("type", "connector", "the server type")
isFrontend := flag.Bool("frontend", true, "if server is frontend")
flag.Parse()
defer pitaya.Shutdown()
ser := protobuf.NewSerializer()
pitaya.SetSerializer(ser)
if !*isFrontend {
configureBackend()
} else {
configureFrontend(*port)
}
pitaya.Configure(*isFrontend, *svType, pitaya.Cluster, map[string]string{})
pitaya.Start()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mixerj/pitaya.git
git@gitee.com:mixerj/pitaya.git
mixerj
pitaya
pitaya
4e7898a663a6

搜索帮助