refactor: reorganize modules and add Linux build tooling
This commit is contained in:
46
module/base/passport/internal/server/account_server.go
Normal file
46
module/base/passport/internal/server/account_server.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/base/passport/internal/logic/account"
|
||||
pb "bsm/full/module/base/passport/pb"
|
||||
)
|
||||
|
||||
type AccountServer struct {
|
||||
pb.UnimplementedAccountServer
|
||||
}
|
||||
|
||||
func NewAccountServer() *AccountServer {
|
||||
return &AccountServer{}
|
||||
}
|
||||
|
||||
// 通过会员所有信息
|
||||
func (s *AccountServer) Get(ctx context.Context, in *pb.Empty) (*pb.GetFullReply, error) {
|
||||
return account.Get(ctx, in)
|
||||
}
|
||||
|
||||
// 更新会员的信息数据,字段值为空或是0,将不更新此数据
|
||||
func (s *AccountServer) SetData(ctx context.Context, in *pb.SetDataRequest) (*pb.StatusReply, error) {
|
||||
return account.SetData(ctx, in)
|
||||
}
|
||||
|
||||
// 更新会员的密码
|
||||
func (s *AccountServer) SetPassword(ctx context.Context, in *pb.SetPasswordRequest) (*pb.StatusReply, error) {
|
||||
return account.SetPassword(ctx, in)
|
||||
}
|
||||
|
||||
// 新增标签
|
||||
func (s *AccountServer) TagCreate(ctx context.Context, in *pb.TagItem) (*pb.StatusReply, error) {
|
||||
return account.TagCreate(ctx, in)
|
||||
}
|
||||
|
||||
// 删除标签
|
||||
func (s *AccountServer) TagRemove(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return account.TagRemove(ctx, in)
|
||||
}
|
||||
|
||||
// 获取会员的相关统计数据
|
||||
func (s *AccountServer) Statistics(ctx context.Context, in *pb.StatisticsRequest) (*pb.StatisticsReply, error) {
|
||||
return account.Statistics(ctx, in)
|
||||
}
|
||||
26
module/base/passport/internal/server/forget_server.go
Normal file
26
module/base/passport/internal/server/forget_server.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/base/passport/internal/logic/forget"
|
||||
pb "bsm/full/module/base/passport/pb"
|
||||
)
|
||||
|
||||
type ForgetServer struct {
|
||||
pb.UnimplementedForgetServer
|
||||
}
|
||||
|
||||
func NewForgetServer() *ForgetServer {
|
||||
return &ForgetServer{}
|
||||
}
|
||||
|
||||
// 验证手机号和验证码
|
||||
func (s *ForgetServer) Verify(ctx context.Context, in *pb.ForgetVerifyRequest) (*pb.StatusReply, error) {
|
||||
return forget.Verify(ctx, in)
|
||||
}
|
||||
|
||||
// 重罢密码
|
||||
func (s *ForgetServer) Reset(ctx context.Context, in *pb.ForgetResetRequest) (*pb.StatusReply, error) {
|
||||
return forget.Reset(ctx, in)
|
||||
}
|
||||
31
module/base/passport/internal/server/login_server.go
Normal file
31
module/base/passport/internal/server/login_server.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/base/passport/internal/logic/login"
|
||||
pb "bsm/full/module/base/passport/pb"
|
||||
)
|
||||
|
||||
type LoginServer struct {
|
||||
pb.UnimplementedLoginServer
|
||||
}
|
||||
|
||||
func NewLoginServer() *LoginServer {
|
||||
return &LoginServer{}
|
||||
}
|
||||
|
||||
// 通过密码登录
|
||||
func (s *LoginServer) Pwd(ctx context.Context, in *pb.LoginByPwdRequest) (*pb.LoginReply, error) {
|
||||
return login.Pwd(ctx, in)
|
||||
}
|
||||
|
||||
// 通过验证码登录
|
||||
func (s *LoginServer) Code(ctx context.Context, in *pb.LoginByCodeRequest) (*pb.LoginReply, error) {
|
||||
return login.Code(ctx, in)
|
||||
}
|
||||
|
||||
// 通过验证码快捷登录并注册
|
||||
func (s *LoginServer) Quick(ctx context.Context, in *pb.LoginByCodeRequest) (*pb.LoginReply, error) {
|
||||
return login.Quick(ctx, in)
|
||||
}
|
||||
111
module/base/passport/internal/server/new.go
Normal file
111
module/base/passport/internal/server/new.go
Normal file
@@ -0,0 +1,111 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "bsm/full/module/base/passport/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/credentials/insecure"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
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)),
|
||||
grpcConns: make(map[string]*grpc.ClientConn),
|
||||
}
|
||||
|
||||
// register service to grpc.Server
|
||||
pb.RegisterAccountServer(srv.Grpc, NewAccountServer())
|
||||
pb.RegisterForgetServer(srv.Grpc, NewForgetServer())
|
||||
pb.RegisterLoginServer(srv.Grpc, NewLoginServer())
|
||||
pb.RegisterRegisterServer(srv.Grpc, NewRegisterServer())
|
||||
pb.RegisterVerifyServer(srv.Grpc, NewVerifyServer())
|
||||
|
||||
reflection.Register(srv.Grpc)
|
||||
|
||||
// 连接池: 只创建一次连接并复用
|
||||
conn, ok := srv.grpcConns[addr]
|
||||
if !ok {
|
||||
var err error
|
||||
conn, err = grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic("failed to dial grpc server: " + err.Error())
|
||||
}
|
||||
srv.grpcConns[addr] = conn
|
||||
}
|
||||
|
||||
// 将服务注册到Gateway
|
||||
|
||||
if err := pb.RegisterAccountHandler(srv.Ctx, srv.Mux, conn); err != nil {
|
||||
panic("Failed to register Account handler: " + err.Error())
|
||||
}
|
||||
|
||||
if err := pb.RegisterForgetHandler(srv.Ctx, srv.Mux, conn); err != nil {
|
||||
panic("Failed to register Forget handler: " + err.Error())
|
||||
}
|
||||
|
||||
if err := pb.RegisterLoginHandler(srv.Ctx, srv.Mux, conn); err != nil {
|
||||
panic("Failed to register Login handler: " + err.Error())
|
||||
}
|
||||
|
||||
if err := pb.RegisterRegisterHandler(srv.Ctx, srv.Mux, conn); err != nil {
|
||||
panic("Failed to register Register handler: " + err.Error())
|
||||
}
|
||||
|
||||
if err := pb.RegisterVerifyHandler(srv.Ctx, srv.Mux, conn); err != nil {
|
||||
panic("Failed to register Verify handler: " + err.Error())
|
||||
}
|
||||
|
||||
// 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": vars.OK,
|
||||
"details": response,
|
||||
"timeseq": time.Now().Unix(),
|
||||
}, nil
|
||||
}
|
||||
26
module/base/passport/internal/server/register_server.go
Normal file
26
module/base/passport/internal/server/register_server.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/base/passport/internal/logic/register"
|
||||
pb "bsm/full/module/base/passport/pb"
|
||||
)
|
||||
|
||||
type RegisterServer struct {
|
||||
pb.UnimplementedRegisterServer
|
||||
}
|
||||
|
||||
func NewRegisterServer() *RegisterServer {
|
||||
return &RegisterServer{}
|
||||
}
|
||||
|
||||
// 帐号密码注册
|
||||
func (s *RegisterServer) Pwd(ctx context.Context, in *pb.RegisterRequest) (*pb.RegisterReply, error) {
|
||||
return register.Pwd(ctx, in)
|
||||
}
|
||||
|
||||
// 手机验证码注册
|
||||
func (s *RegisterServer) Code(ctx context.Context, in *pb.RegisterRequest) (*pb.RegisterReply, error) {
|
||||
return register.Code(ctx, in)
|
||||
}
|
||||
26
module/base/passport/internal/server/verify_server.go
Normal file
26
module/base/passport/internal/server/verify_server.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/base/passport/internal/logic/verify"
|
||||
pb "bsm/full/module/base/passport/pb"
|
||||
)
|
||||
|
||||
type VerifyServer struct {
|
||||
pb.UnimplementedVerifyServer
|
||||
}
|
||||
|
||||
func NewVerifyServer() *VerifyServer {
|
||||
return &VerifyServer{}
|
||||
}
|
||||
|
||||
// 认证请求
|
||||
func (s *VerifyServer) Request(ctx context.Context, in *pb.VerifyRequest) (*pb.StatusReply, error) {
|
||||
return verify.Request(ctx, in)
|
||||
}
|
||||
|
||||
// KYC 认证回调
|
||||
func (s *VerifyServer) JumioCallback(ctx context.Context, in *pb.JumioCallbackPayload) (*pb.StatusReply, error) {
|
||||
return verify.JumioCallback(ctx, in)
|
||||
}
|
||||
Reference in New Issue
Block a user