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/social/feed/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"
|
|
|
|
|
|
"google.golang.org/grpc/reflection"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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-09-22 21:15:34 +08:00
|
|
|
|
func New(grpcServ *grpc.Server) *Server {
|
|
|
|
|
|
// grpcServ 为空表示独立进程启动,自行创建 gRPC Server
|
|
|
|
|
|
standalone := grpcServ == nil
|
|
|
|
|
|
if standalone {
|
|
|
|
|
|
grpcServ = grpc.NewServer()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-09 20:14:57 +08:00
|
|
|
|
srv := &Server{
|
|
|
|
|
|
Ctx: context.Background(),
|
2026-09-22 21:15:34 +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.RegisterPostServer(srv.Grpc, NewPostServer())
|
|
|
|
|
|
pb.RegisterSettingServer(srv.Grpc, NewSettingServer())
|
|
|
|
|
|
pb.RegisterTagServer(srv.Grpc, NewTagServer())
|
|
|
|
|
|
pb.RegisterTimelineServer(srv.Grpc, NewTimelineServer())
|
|
|
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
|
if standalone {
|
|
|
|
|
|
// 独立进程需自行初始化网关路由并注册 handler,否则 /feed.* 全部 404
|
|
|
|
|
|
srv.Mux = gwRuntime.NewServeMux()
|
|
|
|
|
|
if err := RegisterGateway(srv.Ctx, srv.Mux); err != nil {
|
|
|
|
|
|
printer.Error(err.Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
reflection.Register(srv.Grpc)
|
|
|
|
|
|
}
|
2026-08-09 10:43:45 +08:00
|
|
|
|
|
|
|
|
|
|
return srv
|
|
|
|
|
|
}
|
2026-09-22 21:15:34 +08:00
|
|
|
|
|
|
|
|
|
|
// RegisterGateway 注册四个 service 的 gateway handler
|
|
|
|
|
|
func RegisterGateway(ctx context.Context, mux *gwRuntime.ServeMux) error {
|
|
|
|
|
|
if err := pb.RegisterPostHandlerServer(ctx, mux, NewPostServer()); err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
if err := pb.RegisterSettingHandlerServer(ctx, mux, NewSettingServer()); err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
if err := pb.RegisterTagHandlerServer(ctx, mux, NewTagServer()); err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
return pb.RegisterTimelineHandlerServer(ctx, mux, NewTimelineServer())
|
|
|
|
|
|
}
|