1 Star 0 Fork 0

李铭昕/roc-skeleton

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"github.com/hyperf/roc"
"github.com/hyperf/roc/exception"
"github.com/hyperf/roc/formatter"
"github.com/hyperf/roc/log"
"github.com/hyperf/roc/router"
"github.com/hyperf/roc/server"
"github.com/joho/godotenv"
"github.com/limingxinleo/roc-skeleton/action/roc_version"
"go.uber.org/zap"
"time"
)
func SetUpRouters() *router.SimpleRouter {
r := router.NewSimpleRouter()
r.Add("/r_o_c_version/getVersion", &roc_version.GetVersion{})
r.Add("/r_o_c_version/hash", &roc_version.Hash{})
return r
}
func main() {
_ = godotenv.Load()
r := SetUpRouters()
handler := server.NewTcpServerHandler(func(route *formatter.JsonRPCRoute, packet *roc.Packet, server *server.TcpServer) (any, exception.ExceptionInterface) {
name := zap.String("name", "RPC")
log.Logger().Info("RPC_RECEIVED", name, zap.String("path", route.Path))
now := time.Now()
action, ok := r.Routes[route.Path]
if !ok {
log.Logger().Warn("The route is not defined.", name, zap.String("path", route.Path))
return nil, &exception.Exception{Code: exception.NOT_FOUND, Message: "The route is not defined."}
}
ret, e := action.Handle(packet, server.Serializer)
// 记录接口调用时间
t := time.Now().UnixMilli() - now.UnixMilli()
if t > 200 {
log.Logger().Error("RPC_TIME", name, zap.String("path", route.Path), zap.Int64("time", t))
} else {
log.Logger().Info("RPC_TIME", name, zap.String("path", route.Path), zap.Int64("time", t))
}
return ret, e
})
serv := server.NewTcpServer("0.0.0.0:9501", handler)
serv.Start()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/limingxinleo/roc-skeleton.git
git@gitee.com:limingxinleo/roc-skeleton.git
limingxinleo
roc-skeleton
roc-skeleton
main

搜索帮助