pusher/main.go

100 lines
2.6 KiB
Go
Raw Normal View History

2024-05-17 18:02:10 +08:00
package main
import (
2024-05-20 17:57:25 +08:00
"gitea.timerzz.com/kedaya_haitao/pusher/biz/dal"
"gitea.timerzz.com/kedaya_haitao/pusher/pushers"
2024-05-17 18:02:10 +08:00
"net"
"time"
"gitea.timerzz.com/kedaya_haitao/pusher/conf"
"gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/push/pushservice"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/pkg/transmeta"
"github.com/cloudwego/kitex/server"
kitexlogrus "github.com/kitex-contrib/obs-opentelemetry/logging/logrus"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
)
func main() {
2024-05-20 17:57:25 +08:00
dal.Init()
pushers.Init()
2024-05-17 18:02:10 +08:00
opts := kitexInit()
svr := pushservice.NewServer(new(PushServiceImpl), opts...)
err := svr.Run()
if err != nil {
klog.Error(err.Error())
}
}
func kitexInit() (opts []server.Option) {
opts = append(opts, server.
2024-05-20 17:57:25 +08:00
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
2024-05-21 14:01:28 +08:00
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
2024-11-29 21:53:59 +08:00
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
opts = append(opts, server.
2024-05-17 18:02:10 +08:00
WithTransHandlerFactory(&mixTransHandlerFactory{nil}))
// address
addr, err := net.ResolveTCPAddr("tcp", conf.GetConf().Kitex.Address)
if err != nil {
panic(err)
}
opts = append(opts, server.WithServiceAddr(addr))
// service info
opts = append(opts, server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{
ServiceName: conf.GetConf().Kitex.Service,
}))
// thrift meta handler
opts = append(opts, server.WithMetaHandler(transmeta.ServerTTHeaderHandler))
// klog
logger := kitexlogrus.NewLogger()
klog.SetLogger(logger)
klog.SetLevel(conf.LogLevel())
asyncWriter := &zapcore.BufferedWriteSyncer{
WS: zapcore.AddSync(&lumberjack.Logger{
Filename: conf.GetConf().Kitex.LogFileName,
MaxSize: conf.GetConf().Kitex.LogMaxSize,
MaxBackups: conf.GetConf().Kitex.LogMaxBackups,
MaxAge: conf.GetConf().Kitex.LogMaxAge,
}),
FlushInterval: time.Minute,
}
klog.SetOutput(asyncWriter)
server.RegisterShutdownHook(func() {
asyncWriter.Sync()
})
return
}