refactor: reorganize modules and add Linux build tooling

This commit is contained in:
2026-08-09 12:41:08 +08:00
parent 86024fa81d
commit 5cc5fd92ed
1461 changed files with 4054 additions and 4724 deletions

View File

@@ -0,0 +1,77 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"git.apinb.com/bsm-sdk/core/vars"
pb "bsm/full/module/social/feed/pb"
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
}
func New(addr string) *Server {
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux(
gwRuntime.WithForwardResponseRewriter(responseEnvelope),
)}
// 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())
reflection.Register(srv.Grpc)
// 将服务注册到Gateway
opts := []grpc.DialOption{grpc.WithInsecure()}
pb.RegisterPostHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterSettingHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterTagHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterTimelineHandlerFromEndpoint(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
}

View File

@@ -0,0 +1,56 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"bsm/full/module/social/feed/internal/logic/post"
pb "bsm/full/module/social/feed/pb"
)
type PostServer struct {
pb.UnimplementedPostServer
}
func NewPostServer() *PostServer {
return &PostServer{}
}
// 推文列表
func (s *PostServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return post.Fetch(ctx, in)
}
// 新建推文
func (s *PostServer) Create(ctx context.Context, in *pb.PostItem) (*pb.StatusReply, error) {
return post.Create(ctx, in)
}
// 修改推文
func (s *PostServer) Change(ctx context.Context, in *pb.PostItem) (*pb.StatusReply, error) {
return post.Change(ctx, in)
}
// 删除推文
func (s *PostServer) Remove(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
return post.Remove(ctx, in)
}
// 评论列表
func (s *PostServer) CommentList(ctx context.Context, in *pb.FetchRequest) (*pb.CommentListReply, error) {
return post.CommentList(ctx, in)
}
// 新建评论
func (s *PostServer) AddComment(ctx context.Context, in *pb.CommentItem) (*pb.StatusReply, error) {
return post.AddComment(ctx, in)
}
// 删除评论
func (s *PostServer) DeleteComment(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
return post.DeleteComment(ctx, in)
}
// 计数操作
func (s *PostServer) Action(ctx context.Context, in *pb.PostActionRequest) (*pb.StatusReply, error) {
return post.Action(ctx, in)
}

View File

@@ -0,0 +1,26 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"bsm/full/module/social/feed/internal/logic/setting"
pb "bsm/full/module/social/feed/pb"
)
type SettingServer struct {
pb.UnimplementedSettingServer
}
func NewSettingServer() *SettingServer {
return &SettingServer{}
}
// 修改个人信息
func (s *SettingServer) Info(ctx context.Context, in *pb.Empty) (*pb.Empty, error) {
return setting.Info(ctx, in)
}
// 修改权限信息
func (s *SettingServer) Rights(ctx context.Context, in *pb.Empty) (*pb.Empty, error) {
return setting.Rights(ctx, in)
}

View File

@@ -0,0 +1,31 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"bsm/full/module/social/feed/internal/logic/tag"
pb "bsm/full/module/social/feed/pb"
)
type TagServer struct {
pb.UnimplementedTagServer
}
func NewTagServer() *TagServer {
return &TagServer{}
}
// 标签列表
func (s *TagServer) List(ctx context.Context, in *pb.FetchRequest) (*pb.TagListReply, error) {
return tag.List(ctx, in)
}
// 新建标签
func (s *TagServer) Create(ctx context.Context, in *pb.AddTagRequest) (*pb.StatusReply, error) {
return tag.Create(ctx, in)
}
// 话题相关的文章
func (s *TagServer) PostList(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return tag.PostList(ctx, in)
}

View File

@@ -0,0 +1,36 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"bsm/full/module/social/feed/internal/logic/timeline"
pb "bsm/full/module/social/feed/pb"
)
type TimelineServer struct {
pb.UnimplementedTimelineServer
}
func NewTimelineServer() *TimelineServer {
return &TimelineServer{}
}
// 推荐
func (s *TimelineServer) Recommend(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return timeline.Recommend(ctx, in)
}
// 好友动态
func (s *TimelineServer) Friend(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return timeline.Friend(ctx, in)
}
// 关注的动态
func (s *TimelineServer) Follow(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return timeline.Follow(ctx, in)
}
// 热门
func (s *TimelineServer) Hot(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return timeline.Hot(ctx, in)
}