fix version 1

This commit is contained in:
2026-09-22 21:15:34 +08:00
parent 9f86366638
commit d63d7e8b3a
277 changed files with 9959 additions and 1514 deletions

View File

@@ -5,11 +5,25 @@ import (
pb "bsm/full/module/ec/market/pb"
"context"
"git.apinb.com/bsm-sdk/core/printer"
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
)
// recoverUnaryInterceptor 捕获处理过程中的 panic转为 Internal 错误返回,避免进程崩溃。
func recoverUnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
defer func() {
if r := recover(); r != nil {
printer.Error("grpc panic recovered: %v", r)
err = status.Error(codes.Internal, "internal server error")
}
}()
return handler(ctx, req)
}
type Server struct {
Grpc *grpc.Server
Ctx context.Context
@@ -20,7 +34,7 @@ type Server struct {
func New(grpcServ *grpc.Server) *Server {
standalone := grpcServ == nil
if standalone {
grpcServ = grpc.NewServer()
grpcServ = grpc.NewServer(grpc.UnaryInterceptor(recoverUnaryInterceptor))
}
srv := &Server{