代码拉取完成,页面将自动刷新
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()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。