package server import ( "github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/middleware/recovery" "github.com/go-kratos/kratos/v2/middleware/tracing" "github.com/go-kratos/kratos/v2/transport/grpc" "hilo/api/service/user" "hilo/app/service/user/internal/conf" "hilo/app/service/user/internal/handler" "time" ) // NewGRPCServer new a gRPC server. func NewGRPCServer(c *conf.Server, svc *handler.UserService) *grpc.Server { var opts = []grpc.ServerOption{ grpc.Middleware( recovery.Recovery(), tracing.Server(), ValidateParams(), ), } if c.Grpc.Addr != "" { opts = append(opts, grpc.Address(c.Grpc.Addr)) } if c.Grpc.Timeout != 0 { opts = append(opts, grpc.Timeout(time.Duration(c.Grpc.Timeout)*time.Second)) } srv := grpc.NewServer(opts...) user.RegisterUserServer(srv, svc) logHelper = log.NewHelper(log.GetLogger()) return srv }