refactor: localize protobuf definitions

This commit is contained in:
2026-08-09 20:14:57 +08:00
parent 9f6f318bbb
commit 5ea45a76fe
429 changed files with 54058 additions and 61623 deletions

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/social/relation/internal/logic/follow"
pb "bsm/full/module/social/relation/pb"
"context"
)
type FollowServer struct {
@@ -16,17 +16,17 @@ func NewFollowServer() *FollowServer {
}
// 执行关注
func (s *FollowServer) Doing(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FollowServer) Doing(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return follow.Doing(ctx, in)
}
// 撤销关注
func (s *FollowServer) Undo(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FollowServer) Undo(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return follow.Undo(ctx, in)
}
// 关注状态
func (s *FollowServer) State(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FollowServer) State(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return follow.State(ctx, in)
}

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/social/relation/internal/logic/friend"
pb "bsm/full/module/social/relation/pb"
"context"
)
type FriendServer struct {
@@ -31,22 +31,22 @@ func (s *FriendServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.Relati
}
// 修改好友备注名称,如果要清除备注,直接nickname传空值
func (s *FriendServer) ModifyNickname(ctx context.Context, in *pb.ModifyNicknameRequest) (*pb.StatusReply, error) {
func (s *FriendServer) ModifyNickname(ctx context.Context, in *pb.ModifyNicknameRequest) (*pb.DataStatusReply, error) {
return friend.ModifyNickname(ctx, in)
}
// 受你欢迎的,置顶
func (s *FriendServer) DoPopular(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FriendServer) DoPopular(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return friend.DoPopular(ctx, in)
}
// 取消受欢迎的,取消置顶
func (s *FriendServer) UndoPopular(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FriendServer) UndoPopular(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return friend.UndoPopular(ctx, in)
}
// 删除好友
func (s *FriendServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FriendServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return friend.Delete(ctx, in)
}
@@ -61,22 +61,22 @@ func (s *FriendServer) ApplyGet(ctx context.Context, in *pb.IdentRequest) (*pb.F
}
// 好友申请
func (s *FriendServer) ApplyDo(ctx context.Context, in *pb.ApplyDoRequest) (*pb.StatusReply, error) {
func (s *FriendServer) ApplyDo(ctx context.Context, in *pb.ApplyDoRequest) (*pb.DataStatusReply, error) {
return friend.ApplyDo(ctx, in)
}
// 好友申请Do:留言
func (s *FriendServer) ApplyDoMessage(ctx context.Context, in *pb.ApplyMessageRequest) (*pb.StatusReply, error) {
func (s *FriendServer) ApplyDoMessage(ctx context.Context, in *pb.ApplyMessageRequest) (*pb.DataStatusReply, error) {
return friend.ApplyDoMessage(ctx, in)
}
// 好友申请Do:确认
func (s *FriendServer) ApplyDoPass(ctx context.Context, in *pb.ApplyDoPassRequest) (*pb.StatusReply, error) {
func (s *FriendServer) ApplyDoPass(ctx context.Context, in *pb.ApplyDoPassRequest) (*pb.DataStatusReply, error) {
return friend.ApplyDoPass(ctx, in)
}
// 好友申请Do:拒绝
func (s *FriendServer) ApplyDoReject(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FriendServer) ApplyDoReject(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return friend.ApplyDoReject(ctx, in)
}
@@ -91,11 +91,11 @@ func (s *FriendServer) TagMemberFetch(ctx context.Context, in *pb.IdentRequest)
}
// 创建标签
func (s *FriendServer) TagDoCreate(ctx context.Context, in *pb.TagDoCreateRequest) (*pb.StatusReply, error) {
func (s *FriendServer) TagDoCreate(ctx context.Context, in *pb.TagDoCreateRequest) (*pb.DataStatusReply, error) {
return friend.TagDoCreate(ctx, in)
}
// 更新标签成员
func (s *FriendServer) TagDoUpdate(ctx context.Context, in *pb.TagDoUpdateRequest) (*pb.StatusReply, error) {
func (s *FriendServer) TagDoUpdate(ctx context.Context, in *pb.TagDoUpdateRequest) (*pb.DataStatusReply, error) {
return friend.TagDoUpdate(ctx, in)
}

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/social/relation/internal/logic/match"
pb "bsm/full/module/social/relation/pb"
"context"
)
type MatchServer struct {
@@ -26,11 +26,11 @@ func (s *MatchServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.Relatio
}
// 执行通过,加为好友
func (s *MatchServer) DoJoin(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *MatchServer) DoJoin(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return match.DoJoin(ctx, in)
}
// 执行忽略
func (s *MatchServer) DoIgnore(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *MatchServer) DoIgnore(ctx context.Context, in *pb.IdentRequest) (*pb.DataStatusReply, error) {
return match.DoIgnore(ctx, in)
}

View File

@@ -2,28 +2,27 @@
package server
import (
"context"
"git.apinb.com/bsm-sdk/core/vars"
pb "bsm/full/module/social/relation/pb"
"context"
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"google.golang.org/protobuf/proto"
"net/http"
"os"
"strings"
)
type Server struct {
Grpc *grpc.Server
Ctx context.Context
Mux *gwRuntime.ServeMux
Grpc *grpc.Server
Ctx context.Context
Mux *gwRuntime.ServeMux
grpcConns map[string]*grpc.ClientConn // 连接池
}
func New(addr string) *Server {
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux(
gwRuntime.WithForwardResponseRewriter(responseEnvelope),
)}
srv := &Server{
Ctx: context.Background(),
Grpc: grpc.NewServer(),
grpcConns: make(map[string]*grpc.ClientConn),
}
// register service to grpc.Server
pb.RegisterFollowServer(srv.Grpc, NewFollowServer())
@@ -32,44 +31,5 @@ func New(addr string) *Server {
reflection.Register(srv.Grpc)
// 将服务注册到Gateway
opts := []grpc.DialOption{grpc.WithInsecure()}
pb.RegisterFollowHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterFriendHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterMatchHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
// Register services swagger
srv.RegisterSwagger()
return srv
}
// RegisterSwagger 注册swagger
func (s *Server) RegisterSwagger() {
srvKey := strings.ToLower(vars.ServiceKey)
s.Mux.HandlePath("GET", "/"+srvKey+".swagger.json", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
w.Header().Set("Content-Type", "application/json")
bytes, err := os.ReadFile("./swagger/" + srvKey + ".swagger.json")
if err != nil {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(err.Error()))
return
}
w.Write(bytes)
return
})
}
// response envelope
func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) {
name := string(response.ProtoReflect().Descriptor().Name())
if name == "Status" || name == "Error" || name == "StatusReply" {
return response, nil
}
return map[string]any{
"code": 0,
"message": "OK",
"result": response,
}, nil
}