package main import ( "egg-im/config" "egg-im/internal/logic/api" "egg-im/internal/logic/app" "egg-im/internal/logic/proxy" "egg-im/pkg/db" "egg-im/pkg/interceptor" "egg-im/pkg/logger" "egg-im/pkg/pb" "egg-im/pkg/urlwhitelist" "fmt" "net" "os" "os/signal" "syscall" "go.uber.org/zap" "google.golang.org/grpc" ) func init() { proxy.MessageProxy = app.MessageApp proxy.DeviceProxy = app.DeviceApp } func main() { config.Init() db.Init() server := grpc.NewServer(grpc.UnaryInterceptor(interceptor.NewInterceptor("logic_interceptor", urlwhitelist.Logic))) // 监听服务关闭信号,服务平滑重启 go func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM) s := <-c logger.Logger.Info("server stop", zap.Any("signal", s)) server.GracefulStop() }() pb.RegisterLogicIntServer(server, &api.LogicIntServer{}) pb.RegisterLogicExtServer(server, &api.LogicExtServer{}) fmt.Println("logic::listenAddr>>>>", config.RPCListenAddr) listen, err := net.Listen("tcp", config.RPCListenAddr) if err != nil { panic(err) } logger.Logger.Info("rpc服务已经开启") err = server.Serve(listen) if err != nil { logger.Logger.Error("serve error", zap.Error(err)) } }