2026-08-09 10:43:45 +08:00
|
|
|
|
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2026-08-09 12:41:08 +08:00
|
|
|
|
pb "bsm/full/module/ec/market/pb"
|
2026-08-09 20:14:57 +08:00
|
|
|
|
"context"
|
|
|
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
2026-08-09 10:43:45 +08:00
|
|
|
|
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
|
|
|
|
|
"google.golang.org/grpc"
|
2026-09-22 21:15:34 +08:00
|
|
|
|
"google.golang.org/grpc/codes"
|
2026-08-09 10:43:45 +08:00
|
|
|
|
"google.golang.org/grpc/reflection"
|
2026-09-22 21:15:34 +08:00
|
|
|
|
"google.golang.org/grpc/status"
|
2026-08-09 10:43:45 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
|
// 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)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-09 10:43:45 +08:00
|
|
|
|
type Server struct {
|
2026-08-09 20:14:57 +08:00
|
|
|
|
Grpc *grpc.Server
|
|
|
|
|
|
Ctx context.Context
|
|
|
|
|
|
Mux *gwRuntime.ServeMux
|
|
|
|
|
|
grpcConns map[string]*grpc.ClientConn // 连接池
|
2026-08-09 10:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-10 10:03:46 +08:00
|
|
|
|
func New(grpcServ *grpc.Server) *Server {
|
|
|
|
|
|
standalone := grpcServ == nil
|
|
|
|
|
|
if standalone {
|
2026-09-22 21:15:34 +08:00
|
|
|
|
grpcServ = grpc.NewServer(grpc.UnaryInterceptor(recoverUnaryInterceptor))
|
2026-08-10 10:03:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-09 20:14:57 +08:00
|
|
|
|
srv := &Server{
|
|
|
|
|
|
Ctx: context.Background(),
|
2026-08-10 10:03:46 +08:00
|
|
|
|
Grpc: grpcServ,
|
2026-08-09 20:14:57 +08:00
|
|
|
|
grpcConns: make(map[string]*grpc.ClientConn),
|
|
|
|
|
|
}
|
2026-08-09 10:43:45 +08:00
|
|
|
|
|
|
|
|
|
|
// register service to grpc.Server
|
|
|
|
|
|
pb.RegisterAgencyServer(srv.Grpc, NewAgencyServer())
|
|
|
|
|
|
pb.RegisterDataServer(srv.Grpc, NewDataServer())
|
|
|
|
|
|
pb.RegisterSupplyServer(srv.Grpc, NewSupplyServer())
|
|
|
|
|
|
|
2026-08-10 10:03:46 +08:00
|
|
|
|
if standalone {
|
|
|
|
|
|
reflection.Register(srv.Grpc)
|
|
|
|
|
|
}
|
2026-08-09 10:43:45 +08:00
|
|
|
|
|
|
|
|
|
|
return srv
|
|
|
|
|
|
}
|