refactor: reorganize modules and add Linux build tooling
This commit is contained in:
61
module/ec/market/internal/server/agency_server.go
Normal file
61
module/ec/market/internal/server/agency_server.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/ec/market/internal/logic/agency"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
)
|
||||
|
||||
type AgencyServer struct {
|
||||
pb.UnimplementedAgencyServer
|
||||
}
|
||||
|
||||
func NewAgencyServer() *AgencyServer {
|
||||
return &AgencyServer{}
|
||||
}
|
||||
|
||||
// 登录
|
||||
func (s *AgencyServer) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginReply, error) {
|
||||
return agency.Login(ctx, in)
|
||||
}
|
||||
|
||||
// 新增代理商
|
||||
func (s *AgencyServer) Create(ctx context.Context, in *pb.MarketAgenctyItem) (*pb.StatusReply, error) {
|
||||
return agency.Create(ctx, in)
|
||||
}
|
||||
|
||||
// 获取一个代理商
|
||||
func (s *AgencyServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.MarketAgenctyItem, error) {
|
||||
return agency.Get(ctx, in)
|
||||
}
|
||||
|
||||
// 代理商列表
|
||||
func (s *AgencyServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.AgencyReply, error) {
|
||||
return agency.Fetch(ctx, in)
|
||||
}
|
||||
|
||||
// 更新代理商数据
|
||||
func (s *AgencyServer) Modify(ctx context.Context, in *pb.MarketAgenctyItem) (*pb.StatusReply, error) {
|
||||
return agency.Modify(ctx, in)
|
||||
}
|
||||
|
||||
// 删除一个代理商
|
||||
func (s *AgencyServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return agency.Delete(ctx, in)
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
func (s *AgencyServer) SetPassword(ctx context.Context, in *pb.SetPasswordRequest) (*pb.StatusReply, error) {
|
||||
return agency.SetPassword(ctx, in)
|
||||
}
|
||||
|
||||
// 待审核
|
||||
func (s *AgencyServer) Pending(ctx context.Context, in *pb.FetchRequest) (*pb.AgencyReply, error) {
|
||||
return agency.Pending(ctx, in)
|
||||
}
|
||||
|
||||
// 审核
|
||||
func (s *AgencyServer) Approve(ctx context.Context, in *pb.ApproveRequest) (*pb.StatusReply, error) {
|
||||
return agency.Approve(ctx, in)
|
||||
}
|
||||
41
module/ec/market/internal/server/data_server.go
Normal file
41
module/ec/market/internal/server/data_server.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/ec/market/internal/logic/data"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
)
|
||||
|
||||
type DataServer struct {
|
||||
pb.UnimplementedDataServer
|
||||
}
|
||||
|
||||
func NewDataServer() *DataServer {
|
||||
return &DataServer{}
|
||||
}
|
||||
|
||||
// 概况
|
||||
func (s *DataServer) Overview(ctx context.Context, in *pb.Empty) (*pb.OverviewReply, error) {
|
||||
return data.Overview(ctx, in)
|
||||
}
|
||||
|
||||
// 会员列表
|
||||
func (s *DataServer) MemberFetch(ctx context.Context, in *pb.FetchRequest) (*pb.DataReply, error) {
|
||||
return data.MemberFetch(ctx, in)
|
||||
}
|
||||
|
||||
// 会员详情
|
||||
func (s *DataServer) MemberDetails(ctx context.Context, in *pb.IdentRequest) (*pb.KeyVal, error) {
|
||||
return data.MemberDetails(ctx, in)
|
||||
}
|
||||
|
||||
// 订单列表
|
||||
func (s *DataServer) OrderFetch(ctx context.Context, in *pb.FetchRequest) (*pb.DataReply, error) {
|
||||
return data.OrderFetch(ctx, in)
|
||||
}
|
||||
|
||||
// 订单详情
|
||||
func (s *DataServer) OrderDetails(ctx context.Context, in *pb.IdentRequest) (*pb.KeyVal, error) {
|
||||
return data.OrderDetails(ctx, in)
|
||||
}
|
||||
75
module/ec/market/internal/server/new.go
Normal file
75
module/ec/market/internal/server/new.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
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.RegisterAgencyServer(srv.Grpc, NewAgencyServer())
|
||||
pb.RegisterDataServer(srv.Grpc, NewDataServer())
|
||||
pb.RegisterSupplyServer(srv.Grpc, NewSupplyServer())
|
||||
|
||||
reflection.Register(srv.Grpc)
|
||||
|
||||
// 将服务注册到Gateway
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
pb.RegisterAgencyHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterDataHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterSupplyHandlerFromEndpoint(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
|
||||
}
|
||||
41
module/ec/market/internal/server/supply_server.go
Normal file
41
module/ec/market/internal/server/supply_server.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/ec/market/internal/logic/supply"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
)
|
||||
|
||||
type SupplyServer struct {
|
||||
pb.UnimplementedSupplyServer
|
||||
}
|
||||
|
||||
func NewSupplyServer() *SupplyServer {
|
||||
return &SupplyServer{}
|
||||
}
|
||||
|
||||
// 新增供应商
|
||||
func (s *SupplyServer) Create(ctx context.Context, in *pb.MarketSupplyItem) (*pb.StatusReply, error) {
|
||||
return supply.Create(ctx, in)
|
||||
}
|
||||
|
||||
// 获取一个供应商
|
||||
func (s *SupplyServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.MarketSupplyItem, error) {
|
||||
return supply.Get(ctx, in)
|
||||
}
|
||||
|
||||
// 供应商列表
|
||||
func (s *SupplyServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.SupplyReply, error) {
|
||||
return supply.Fetch(ctx, in)
|
||||
}
|
||||
|
||||
// 更新供应商数据
|
||||
func (s *SupplyServer) Modify(ctx context.Context, in *pb.MarketSupplyItem) (*pb.StatusReply, error) {
|
||||
return supply.Modify(ctx, in)
|
||||
}
|
||||
|
||||
// 删除一个供应商
|
||||
func (s *SupplyServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return supply.Delete(ctx, in)
|
||||
}
|
||||
Reference in New Issue
Block a user