From e679899a57a96b48c6bf740a22fbac9652646087 Mon Sep 17 00:00:00 2001 From: kzkzzzz Date: Fri, 10 Jun 2022 18:40:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/member/member.pb.go | 279 ++++++++++++ api/member/member.pb.micro.go | 88 ++++ api/member/member.proto | 26 ++ api/wallet/wallet.pb.go | 425 ++++++++++++++++++ api/wallet/wallet.pb.micro.go | 105 +++++ api/wallet/wallet.proto | 35 ++ service/member/.air.toml | 37 ++ service/member/.gitignore | 4 + service/member/config/config.yaml | 24 + service/member/internal/conf/conf.go | 39 ++ service/member/internal/dao/dao.go | 33 ++ .../internal/model/ims_db_play_member.go | 90 ++++ service/member/internal/model/users.go | 24 + service/member/internal/server/grpc.go | 38 ++ service/member/internal/server/handler.go | 47 ++ service/member/internal/service/service.go | 27 ++ service/member/main.go | 52 +++ service/wallet/.air.toml | 37 ++ service/wallet/.gitignore | 4 + service/wallet/client/client.go | 42 ++ service/wallet/client/middleware.go | 21 + service/wallet/config/config.yaml | 28 ++ service/wallet/internal/conf/conf.go | 44 ++ service/wallet/internal/dao/dao.go | 39 ++ service/wallet/internal/model/users.go | 24 + service/wallet/internal/server/grpc.go | 38 ++ service/wallet/internal/server/handler.go | 60 +++ service/wallet/internal/service/service.go | 52 +++ service/wallet/main.go | 55 +++ 29 files changed, 1817 insertions(+) create mode 100644 api/member/member.pb.go create mode 100644 api/member/member.pb.micro.go create mode 100644 api/member/member.proto create mode 100644 api/wallet/wallet.pb.go create mode 100644 api/wallet/wallet.pb.micro.go create mode 100644 api/wallet/wallet.proto create mode 100644 service/member/.air.toml create mode 100644 service/member/.gitignore create mode 100644 service/member/config/config.yaml create mode 100644 service/member/internal/conf/conf.go create mode 100644 service/member/internal/dao/dao.go create mode 100644 service/member/internal/model/ims_db_play_member.go create mode 100644 service/member/internal/model/users.go create mode 100644 service/member/internal/server/grpc.go create mode 100644 service/member/internal/server/handler.go create mode 100644 service/member/internal/service/service.go create mode 100644 service/member/main.go create mode 100644 service/wallet/.air.toml create mode 100644 service/wallet/.gitignore create mode 100644 service/wallet/client/client.go create mode 100644 service/wallet/client/middleware.go create mode 100644 service/wallet/config/config.yaml create mode 100644 service/wallet/internal/conf/conf.go create mode 100644 service/wallet/internal/dao/dao.go create mode 100644 service/wallet/internal/model/users.go create mode 100644 service/wallet/internal/server/grpc.go create mode 100644 service/wallet/internal/server/handler.go create mode 100644 service/wallet/internal/service/service.go create mode 100644 service/wallet/main.go diff --git a/api/member/member.pb.go b/api/member/member.pb.go new file mode 100644 index 0000000..99df3fb --- /dev/null +++ b/api/member/member.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.20.1 +// source: member.proto + +package member + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + _ "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type MemberInfoReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserId int64 `protobuf:"varint,1,opt,name=userId,proto3" json:"userId" validate:"required"` // @gotags: validate:"required" + Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token" validate:"required"` // @gotags: validate:"required" +} + +func (x *MemberInfoReq) Reset() { + *x = MemberInfoReq{} + if protoimpl.UnsafeEnabled { + mi := &file_member_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MemberInfoReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MemberInfoReq) ProtoMessage() {} + +func (x *MemberInfoReq) ProtoReflect() protoreflect.Message { + mi := &file_member_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MemberInfoReq.ProtoReflect.Descriptor instead. +func (*MemberInfoReq) Descriptor() ([]byte, []int) { + return file_member_proto_rawDescGZIP(), []int{0} +} + +func (x *MemberInfoReq) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *MemberInfoReq) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +type MemberInfoResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserId int64 `protobuf:"varint,1,opt,name=userId,proto3" json:"userId"` + UserNo int64 `protobuf:"varint,2,opt,name=userNo,proto3" json:"userNo"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name"` + Avatar string `protobuf:"bytes,4,opt,name=avatar,proto3" json:"avatar"` + Coins int64 `protobuf:"varint,5,opt,name=coins,proto3" json:"coins"` + CoinIcon string `protobuf:"bytes,6,opt,name=coinIcon,proto3" json:"coinIcon"` + RoomId string `protobuf:"bytes,7,opt,name=roomId,proto3" json:"roomId"` +} + +func (x *MemberInfoResp) Reset() { + *x = MemberInfoResp{} + if protoimpl.UnsafeEnabled { + mi := &file_member_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MemberInfoResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MemberInfoResp) ProtoMessage() {} + +func (x *MemberInfoResp) ProtoReflect() protoreflect.Message { + mi := &file_member_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MemberInfoResp.ProtoReflect.Descriptor instead. +func (*MemberInfoResp) Descriptor() ([]byte, []int) { + return file_member_proto_rawDescGZIP(), []int{1} +} + +func (x *MemberInfoResp) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *MemberInfoResp) GetUserNo() int64 { + if x != nil { + return x.UserNo + } + return 0 +} + +func (x *MemberInfoResp) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *MemberInfoResp) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *MemberInfoResp) GetCoins() int64 { + if x != nil { + return x.Coins + } + return 0 +} + +func (x *MemberInfoResp) GetCoinIcon() string { + if x != nil { + return x.CoinIcon + } + return "" +} + +func (x *MemberInfoResp) GetRoomId() string { + if x != nil { + return x.RoomId + } + return "" +} + +var File_member_proto protoreflect.FileDescriptor + +var file_member_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, + 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x3d, 0x0a, 0x0d, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, + 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0xb6, + 0x01, 0x0a, 0x0e, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, + 0x70, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, + 0x72, 0x4e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x4e, + 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x14, 0x0a, + 0x05, 0x63, 0x6f, 0x69, 0x6e, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, + 0x69, 0x6e, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6f, 0x69, 0x6e, 0x49, 0x63, 0x6f, 0x6e, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x6f, 0x69, 0x6e, 0x49, 0x63, 0x6f, 0x6e, 0x12, + 0x16, 0x0a, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x49, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x49, 0x64, 0x32, 0x3c, 0x0a, 0x06, 0x4d, 0x65, 0x6d, 0x62, 0x65, + 0x72, 0x12, 0x32, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x49, 0x6e, + 0x66, 0x6f, 0x12, 0x0e, 0x2e, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, + 0x65, 0x71, 0x1a, 0x0f, 0x2e, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, + 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x3b, 0x6d, 0x65, 0x6d, 0x62, + 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_member_proto_rawDescOnce sync.Once + file_member_proto_rawDescData = file_member_proto_rawDesc +) + +func file_member_proto_rawDescGZIP() []byte { + file_member_proto_rawDescOnce.Do(func() { + file_member_proto_rawDescData = protoimpl.X.CompressGZIP(file_member_proto_rawDescData) + }) + return file_member_proto_rawDescData +} + +var file_member_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_member_proto_goTypes = []interface{}{ + (*MemberInfoReq)(nil), // 0: MemberInfoReq + (*MemberInfoResp)(nil), // 1: MemberInfoResp +} +var file_member_proto_depIdxs = []int32{ + 0, // 0: Member.GetMemberInfo:input_type -> MemberInfoReq + 1, // 1: Member.GetMemberInfo:output_type -> MemberInfoResp + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_member_proto_init() } +func file_member_proto_init() { + if File_member_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_member_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MemberInfoReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_member_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MemberInfoResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_member_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_member_proto_goTypes, + DependencyIndexes: file_member_proto_depIdxs, + MessageInfos: file_member_proto_msgTypes, + }.Build() + File_member_proto = out.File + file_member_proto_rawDesc = nil + file_member_proto_goTypes = nil + file_member_proto_depIdxs = nil +} diff --git a/api/member/member.pb.micro.go b/api/member/member.pb.micro.go new file mode 100644 index 0000000..da7fb68 --- /dev/null +++ b/api/member/member.pb.micro.go @@ -0,0 +1,88 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: member.proto + +package member + +import ( + fmt "fmt" + proto "google.golang.org/protobuf/proto" + _ "google.golang.org/protobuf/types/known/timestamppb" + math "math" +) + +import ( + context "context" + api "go-micro.dev/v4/api" + client "go-micro.dev/v4/client" + server "go-micro.dev/v4/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint +var _ context.Context +var _ client.Option +var _ server.Option + +// Api Endpoints for Member service + +func NewMemberEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + +// Client API for Member service + +type MemberService interface { + GetMemberInfo(ctx context.Context, in *MemberInfoReq, opts ...client.CallOption) (*MemberInfoResp, error) +} + +type memberService struct { + c client.Client + name string +} + +func NewMemberService(name string, c client.Client) MemberService { + return &memberService{ + c: c, + name: name, + } +} + +func (c *memberService) GetMemberInfo(ctx context.Context, in *MemberInfoReq, opts ...client.CallOption) (*MemberInfoResp, error) { + req := c.c.NewRequest(c.name, "Member.GetMemberInfo", in) + out := new(MemberInfoResp) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Member service + +type MemberHandler interface { + GetMemberInfo(context.Context, *MemberInfoReq, *MemberInfoResp) error +} + +func RegisterMemberHandler(s server.Server, hdlr MemberHandler, opts ...server.HandlerOption) error { + type member interface { + GetMemberInfo(ctx context.Context, in *MemberInfoReq, out *MemberInfoResp) error + } + type Member struct { + member + } + h := &memberHandler{hdlr} + return s.Handle(s.NewHandler(&Member{h}, opts...)) +} + +type memberHandler struct { + MemberHandler +} + +func (h *memberHandler) GetMemberInfo(ctx context.Context, in *MemberInfoReq, out *MemberInfoResp) error { + return h.MemberHandler.GetMemberInfo(ctx, in, out) +} diff --git a/api/member/member.proto b/api/member/member.proto new file mode 100644 index 0000000..e3a9dd1 --- /dev/null +++ b/api/member/member.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; + +import "google/protobuf/timestamp.proto"; + +option go_package = "./;member"; + + +message MemberInfoReq { + int64 userId = 1; // @gotags: validate:"required" + string token = 2; // @gotags: validate:"required" +} + +message MemberInfoResp { + int64 userId = 1; + int64 userNo = 2; + string name = 3; + string avatar = 4; + int64 coins = 5; + string coinIcon = 6; + string roomId = 7; +} + +service Member { + rpc GetMemberInfo(MemberInfoReq) returns (MemberInfoResp){}; +} + diff --git a/api/wallet/wallet.pb.go b/api/wallet/wallet.pb.go new file mode 100644 index 0000000..eb556b5 --- /dev/null +++ b/api/wallet/wallet.pb.go @@ -0,0 +1,425 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.20.1 +// source: wallet.proto + +package wallet + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type WalletReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" validate:"required"` // @gotags: validate:"required" +} + +func (x *WalletReq) Reset() { + *x = WalletReq{} + if protoimpl.UnsafeEnabled { + mi := &file_wallet_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *WalletReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WalletReq) ProtoMessage() {} + +func (x *WalletReq) ProtoReflect() protoreflect.Message { + mi := &file_wallet_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use WalletReq.ProtoReflect.Descriptor instead. +func (*WalletReq) Descriptor() ([]byte, []int) { + return file_wallet_proto_rawDescGZIP(), []int{0} +} + +func (x *WalletReq) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type ListWalletReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" validate:"required"` // @gotags: validate:"required" + Limit int32 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit"` +} + +func (x *ListWalletReq) Reset() { + *x = ListWalletReq{} + if protoimpl.UnsafeEnabled { + mi := &file_wallet_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListWalletReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListWalletReq) ProtoMessage() {} + +func (x *ListWalletReq) ProtoReflect() protoreflect.Message { + mi := &file_wallet_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListWalletReq.ProtoReflect.Descriptor instead. +func (*ListWalletReq) Descriptor() ([]byte, []int) { + return file_wallet_proto_rawDescGZIP(), []int{1} +} + +func (x *ListWalletReq) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *ListWalletReq) GetLimit() int32 { + if x != nil { + return x.Limit + } + return 0 +} + +type WalletResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id"` + Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username"` + Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email"` + Avatar string `protobuf:"bytes,4,opt,name=avatar,proto3" json:"avatar"` + Status int32 `protobuf:"varint,5,opt,name=status,proto3" json:"status"` + CreatedAt *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=created_at,json=createdAt,proto3" json:"created_at"` + UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at"` +} + +func (x *WalletResp) Reset() { + *x = WalletResp{} + if protoimpl.UnsafeEnabled { + mi := &file_wallet_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *WalletResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WalletResp) ProtoMessage() {} + +func (x *WalletResp) ProtoReflect() protoreflect.Message { + mi := &file_wallet_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use WalletResp.ProtoReflect.Descriptor instead. +func (*WalletResp) Descriptor() ([]byte, []int) { + return file_wallet_proto_rawDescGZIP(), []int{2} +} + +func (x *WalletResp) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *WalletResp) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +func (x *WalletResp) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *WalletResp) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *WalletResp) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *WalletResp) GetCreatedAt() *timestamppb.Timestamp { + if x != nil { + return x.CreatedAt + } + return nil +} + +func (x *WalletResp) GetUpdatedAt() *timestamppb.Timestamp { + if x != nil { + return x.UpdatedAt + } + return nil +} + +type ListWalletResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + List []*WalletResp `protobuf:"bytes,1,rep,name=list,proto3" json:"list"` + Limit int32 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit"` +} + +func (x *ListWalletResp) Reset() { + *x = ListWalletResp{} + if protoimpl.UnsafeEnabled { + mi := &file_wallet_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListWalletResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListWalletResp) ProtoMessage() {} + +func (x *ListWalletResp) ProtoReflect() protoreflect.Message { + mi := &file_wallet_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListWalletResp.ProtoReflect.Descriptor instead. +func (*ListWalletResp) Descriptor() ([]byte, []int) { + return file_wallet_proto_rawDescGZIP(), []int{3} +} + +func (x *ListWalletResp) GetList() []*WalletResp { + if x != nil { + return x.List + } + return nil +} + +func (x *ListWalletResp) GetLimit() int32 { + if x != nil { + return x.Limit + } + return 0 +} + +var File_wallet_proto protoreflect.FileDescriptor + +var file_wallet_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, + 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x1b, 0x0a, 0x09, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x35, 0x0a, 0x0d, + 0x4c, 0x69, 0x73, 0x74, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, + 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x22, 0xf4, 0x01, 0x0a, 0x0a, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, + 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, + 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x16, 0x0a, 0x06, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, + 0x61, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, + 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x22, 0x47, 0x0a, 0x0e, 0x4c, 0x69, + 0x73, 0x74, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1f, 0x0a, 0x04, + 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x57, 0x61, 0x6c, + 0x6c, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x14, 0x0a, + 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x32, 0x61, 0x0a, 0x06, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x12, 0x26, 0x0a, + 0x09, 0x47, 0x65, 0x74, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x12, 0x0a, 0x2e, 0x57, 0x61, 0x6c, + 0x6c, 0x65, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x0b, 0x2e, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x0a, 0x4c, 0x69, 0x73, 0x74, 0x57, 0x61, 0x6c, + 0x6c, 0x65, 0x74, 0x12, 0x0e, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, + 0x52, 0x65, 0x71, 0x1a, 0x0f, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x3b, 0x77, 0x61, 0x6c, + 0x6c, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_wallet_proto_rawDescOnce sync.Once + file_wallet_proto_rawDescData = file_wallet_proto_rawDesc +) + +func file_wallet_proto_rawDescGZIP() []byte { + file_wallet_proto_rawDescOnce.Do(func() { + file_wallet_proto_rawDescData = protoimpl.X.CompressGZIP(file_wallet_proto_rawDescData) + }) + return file_wallet_proto_rawDescData +} + +var file_wallet_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_wallet_proto_goTypes = []interface{}{ + (*WalletReq)(nil), // 0: WalletReq + (*ListWalletReq)(nil), // 1: ListWalletReq + (*WalletResp)(nil), // 2: WalletResp + (*ListWalletResp)(nil), // 3: ListWalletResp + (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp +} +var file_wallet_proto_depIdxs = []int32{ + 4, // 0: WalletResp.created_at:type_name -> google.protobuf.Timestamp + 4, // 1: WalletResp.updated_at:type_name -> google.protobuf.Timestamp + 2, // 2: ListWalletResp.list:type_name -> WalletResp + 0, // 3: Wallet.GetWallet:input_type -> WalletReq + 1, // 4: Wallet.ListWallet:input_type -> ListWalletReq + 2, // 5: Wallet.GetWallet:output_type -> WalletResp + 3, // 6: Wallet.ListWallet:output_type -> ListWalletResp + 5, // [5:7] is the sub-list for method output_type + 3, // [3:5] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_wallet_proto_init() } +func file_wallet_proto_init() { + if File_wallet_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_wallet_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*WalletReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_wallet_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListWalletReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_wallet_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*WalletResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_wallet_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListWalletResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_wallet_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_wallet_proto_goTypes, + DependencyIndexes: file_wallet_proto_depIdxs, + MessageInfos: file_wallet_proto_msgTypes, + }.Build() + File_wallet_proto = out.File + file_wallet_proto_rawDesc = nil + file_wallet_proto_goTypes = nil + file_wallet_proto_depIdxs = nil +} diff --git a/api/wallet/wallet.pb.micro.go b/api/wallet/wallet.pb.micro.go new file mode 100644 index 0000000..bf525a6 --- /dev/null +++ b/api/wallet/wallet.pb.micro.go @@ -0,0 +1,105 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: wallet.proto + +package wallet + +import ( + fmt "fmt" + proto "google.golang.org/protobuf/proto" + _ "google.golang.org/protobuf/types/known/timestamppb" + math "math" +) + +import ( + context "context" + api "go-micro.dev/v4/api" + client "go-micro.dev/v4/client" + server "go-micro.dev/v4/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint +var _ context.Context +var _ client.Option +var _ server.Option + +// Api Endpoints for Wallet service + +func NewWalletEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + +// Client API for Wallet service + +type WalletService interface { + GetWallet(ctx context.Context, in *WalletReq, opts ...client.CallOption) (*WalletResp, error) + ListWallet(ctx context.Context, in *ListWalletReq, opts ...client.CallOption) (*ListWalletResp, error) +} + +type walletService struct { + c client.Client + name string +} + +func NewWalletService(name string, c client.Client) WalletService { + return &walletService{ + c: c, + name: name, + } +} + +func (c *walletService) GetWallet(ctx context.Context, in *WalletReq, opts ...client.CallOption) (*WalletResp, error) { + req := c.c.NewRequest(c.name, "Wallet.GetWallet", in) + out := new(WalletResp) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *walletService) ListWallet(ctx context.Context, in *ListWalletReq, opts ...client.CallOption) (*ListWalletResp, error) { + req := c.c.NewRequest(c.name, "Wallet.ListWallet", in) + out := new(ListWalletResp) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Wallet service + +type WalletHandler interface { + GetWallet(context.Context, *WalletReq, *WalletResp) error + ListWallet(context.Context, *ListWalletReq, *ListWalletResp) error +} + +func RegisterWalletHandler(s server.Server, hdlr WalletHandler, opts ...server.HandlerOption) error { + type wallet interface { + GetWallet(ctx context.Context, in *WalletReq, out *WalletResp) error + ListWallet(ctx context.Context, in *ListWalletReq, out *ListWalletResp) error + } + type Wallet struct { + wallet + } + h := &walletHandler{hdlr} + return s.Handle(s.NewHandler(&Wallet{h}, opts...)) +} + +type walletHandler struct { + WalletHandler +} + +func (h *walletHandler) GetWallet(ctx context.Context, in *WalletReq, out *WalletResp) error { + return h.WalletHandler.GetWallet(ctx, in, out) +} + +func (h *walletHandler) ListWallet(ctx context.Context, in *ListWalletReq, out *ListWalletResp) error { + return h.WalletHandler.ListWallet(ctx, in, out) +} diff --git a/api/wallet/wallet.proto b/api/wallet/wallet.proto new file mode 100644 index 0000000..011b45b --- /dev/null +++ b/api/wallet/wallet.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; + +import "google/protobuf/timestamp.proto"; + +option go_package = "./;wallet"; + +message WalletReq { + string id = 1; // @gotags: validate:"required" +} + +message ListWalletReq { + string id = 1; // @gotags: validate:"required" + int32 limit = 2; +} + +message WalletResp { + string id = 1; + string username = 2; + string email = 3; + string avatar = 4; + int32 status = 5; + google.protobuf.Timestamp created_at = 6; + google.protobuf.Timestamp updated_at = 7; +} + +message ListWalletResp { + repeated WalletResp list = 1; + int32 limit = 2; +} + +service Wallet { + rpc GetWallet(WalletReq) returns (WalletResp){}; + rpc ListWallet(ListWalletReq) returns (ListWalletResp){}; +} + diff --git a/service/member/.air.toml b/service/member/.air.toml new file mode 100644 index 0000000..89b070d --- /dev/null +++ b/service/member/.air.toml @@ -0,0 +1,37 @@ +# air热更新https://github.com/cosmtrek/air 或者 使用go-micro +root = "." +testdata_dir = "testdata" +tmp_dir = "bin" + +[build] +bin = "./bin/server" +cmd = "go build -o ./bin/server ." +delay = 100 +exclude_dir = ["assets", "tmp", "vendor", "testdata"] +exclude_file = [] +exclude_regex = ["_test.go"] +exclude_unchanged = false +follow_symlink = false +full_bin = "" +include_dir = [] +include_ext = ["go", "tpl", "tmpl", "html"] +kill_delay = 100 +log = "build-errors.log" +send_interrupt = true +stop_on_error = true + +[color] +app = "" +build = "yellow" +main = "magenta" +runner = "green" +watcher = "cyan" + +[log] +time = true + +[misc] +clean_on_exit = false + +[screen] +clear_on_rebuild = false diff --git a/service/member/.gitignore b/service/member/.gitignore new file mode 100644 index 0000000..cd38e0a --- /dev/null +++ b/service/member/.gitignore @@ -0,0 +1,4 @@ +tmp +temp +bin +*.log \ No newline at end of file diff --git a/service/member/config/config.yaml b/service/member/config/config.yaml new file mode 100644 index 0000000..d709d90 --- /dev/null +++ b/service/member/config/config.yaml @@ -0,0 +1,24 @@ +Server: + Name: "service.member" + ConsulServer: + - 192.168.233.1:8500 + Grpc: + Addr: "" # 为空随机端口, 使用注册中心服务发现 + Http: + Addr: "" + +Mysql: + Dsn: master:Xt6fW2rNRvYZjtYW@tcp(rm-j6c982j8ih8x3d2yz2o.mysql.rds.aliyuncs.com:3306)/master?loc=Local&charset=utf8mb4&writeTimeout=3s&readTimeout=3s&timeout=2s&parseTime=true + MaxConn: 8 + MaxIdleConn: 2 + MaxLifetime: 1800 # 连接有效时间,单位秒 + Debug: true + +Redis: + Addr: 127.0.0.1:6379 + Password: "" + DB: 15 + +Log: + Color: true + Level: DEBUG \ No newline at end of file diff --git a/service/member/internal/conf/conf.go b/service/member/internal/conf/conf.go new file mode 100644 index 0000000..c18a4a7 --- /dev/null +++ b/service/member/internal/conf/conf.go @@ -0,0 +1,39 @@ +package conf + +import ( + "flag" + "gomicro-base/common/conf" + "gomicro-base/common/logz" + "gomicro-base/common/mysql" +) + +func init() { + flag.StringVar(&confPath, "conf", "config/config.yaml", "配置文件路径") +} + +var ( + confPath string + Conf = &Config{} +) + +type Config struct { + Server *Server + Mysql *mysql.Config + Log *logz.Config +} + +type Server struct { + Name string + ConsulServer []string + EtcdServer []string + Grpc struct { + Addr string + } + Http struct { + Addr string + } +} + +func LoadConfig() { + conf.LoadFromYaml(confPath, &Conf) +} diff --git a/service/member/internal/dao/dao.go b/service/member/internal/dao/dao.go new file mode 100644 index 0000000..97a09e4 --- /dev/null +++ b/service/member/internal/dao/dao.go @@ -0,0 +1,33 @@ +package dao + +import ( + "gomicro-base/common/mysql" + "gomicro-base/service/member/internal/conf" + "gomicro-base/service/member/internal/model" + "gorm.io/gorm" +) + +// Dao 查询数据库 +type Dao struct { + DB *gorm.DB +} + +func New(c *conf.Config) (d *Dao) { + d = &Dao{ + DB: mysql.NewDB(c.Mysql), + } + return +} + +// GetMemberById 根据id查询用户 +func (d *Dao) GetMemberById(id int, token string, column []string) (res *model.ImsDbPlayMember, err error) { + res = &model.ImsDbPlayMember{} + err = d.DB.Model(&model.ImsDbPlayMember{}). + Select(column). + Where(map[string]interface{}{ + "id": id, + "token": token, + }). + Take(res).Error + return +} diff --git a/service/member/internal/model/ims_db_play_member.go b/service/member/internal/model/ims_db_play_member.go new file mode 100644 index 0000000..b1ff263 --- /dev/null +++ b/service/member/internal/model/ims_db_play_member.go @@ -0,0 +1,90 @@ +package model + +type ImsDbPlayMember struct { + Id int `json:"id"` // Id + UserNo int `json:"user_no"` // 用户编号 + QqOpenid string `json:"qq_openid"` // QQ的openid + Openid string `json:"openid"` // openid 微信唯一标识 + UnionId string `json:"union_id"` // UnionId + FaceId int64 `json:"face_id"` // facebook的用户id + GoogleId string `json:"google_id"` // 谷歌登录用户id + Nickname string `json:"nickname"` // 会员昵称 + Realname string `json:"realname"` // 真实姓名 + Zfb string `json:"zfb"` // 支付宝账号 + Mobile string `json:"mobile"` // 手机号码 + Avatar string `json:"avatar"` // 头像 + AvatarOld string `json:"avatar_old"` // AvatarOld + Sex int `json:"sex"` // 性别 0.保密 1.男 2.女 + Password string `json:"password"` // 密码 + Credit1 float64 `json:"credit1"` // 金币余额 + Credit2 float64 `json:"credit2"` // 可提现的钻石 + Credit3 float64 `json:"credit3"` // 总收益的钻石 + Credit4 float64 `json:"credit4"` // 代理金币余额,0没有额度限制大于零有额度限制 + LocationP string `json:"location_p"` // 省 + BirthYear string `json:"birth_year"` // 出生年 + MoneyTime int `json:"money_time"` // MoneyTime + FamilyTime int `json:"family_time"` // 家族收入点击时间 + NewseeTime int `json:"newsee_time"` // NewseeTime + NewfansTime int `json:"newfans_time"` // NewfansTime + InviteTime int `json:"invite_time"` // 邀请收入点击时间 + Createtime int `json:"createtime"` // 创建时间 + Sign string `json:"sign"` // 个性签名 + PushId string `json:"push_id"` // 设备号 + Token string `json:"token"` // app登陆验证 + IdCard string `json:"id_card"` // IdCard + Exp float64 `json:"exp"` // 经验值 + VipTime int `json:"vip_time"` // 最后消费时间 + ActiveValue float64 `json:"active_value"` // ActiveValue + CharmValue float64 `json:"charm_value"` // 魅力值 + ContributionValue float64 `json:"contribution_value"` // 贡献值 + City string `json:"city"` // 所在的城市 + Country string `json:"country"` // 国家 + CountryTime int `json:"country_time"` // CountryTime + Love string `json:"love"` // 爱好 + Tip string `json:"tip"` // 标签 + RoomNumber int `json:"room_number"` // RoomNumber + IsHire int `json:"is_hire"` // 0未签约1签约 + FamilyId int `json:"family_id"` // FamilyId + Spread int `json:"spread"` // 1非推广员2推广员 + LoginTime int `json:"login_time"` // 最新登录时间 + LoginIp string `json:"login_ip"` // 登录ip + FollowNumber int `json:"follow_number"` // 关注数量 + FansNumber int `json:"fans_number"` // 粉丝数量 + SeeNumber int `json:"see_number"` // 查看数量 + NoReadIncome float64 `json:"no_read_income"` // 距离上一次未查看的收入 + NewFansNumber int `json:"new_fans_number"` // 新的查看数量 + NewSeeNumber int `json:"new_see_number"` // 新的查看用户数 + Channel string `json:"channel"` // 渠道注册信息 + AdId string `json:"ad_id"` // 广告ID + IsNumber int `json:"is_number"` // 是否是特殊靓号,1:否,2:是 + CountryType int `json:"country_type"` // 1国内2国外 + Region string `json:"region"` // Region + Mailbox string `json:"mailbox"` // 邮箱 + TransferNumber int `json:"transfer_number"` // TransferNumber + TransferDollar int `json:"transfer_dollar"` // 充值美元数 + TransferMoney int64 `json:"transfer_money"` // 已充值金币数 + Agent int `json:"agent"` // 1是代理2非代理 + IsAdmin int `json:"is_admin"` // 0否1是 + UpdateTime int `json:"update_time"` // 更新时间 + ClientVersion string `json:"client_version"` // ClientVersion + PhoneName string `json:"phone_name"` // PhoneName + PhoneVersion string `json:"phone_version"` // PhoneVersion + GroupId int `json:"group_id"` // 分组id + Vip int `json:"vip"` // vip 等级 + Anchor int `json:"anchor"` // 是否为主播 + PkMoney float64 `json:"pk_money"` // pk所赢的钻石 + PkNumber int `json:"pk_number"` // pk胜利的次数 + ScoreTime int `json:"score_time"` // 评分时间 + GoTime int `json:"go_time"` // 是否被引导去过 + FirstTime int `json:"first_time"` // FirstTime + Device string `json:"device"` // Device + AppleId string `json:"apple_id"` // 苹果id + RegisterType int `json:"register_type"` // 1facebook2google3手机号4微信5qq6苹果7手机号8华为 + TrackerName string `json:"tracker_name"` // TrackerName + CampaignName string `json:"campaign_name"` // CampaignName + SnapchatId string `json:"snapchat_id"` // SnapchatId +} + +func (i *ImsDbPlayMember) TableName() string { + return "ims_db_play_member" +} diff --git a/service/member/internal/model/users.go b/service/member/internal/model/users.go new file mode 100644 index 0000000..af75b4a --- /dev/null +++ b/service/member/internal/model/users.go @@ -0,0 +1,24 @@ +package model + +import ( + "time" +) + +type User struct { + Id int `json:"id"` // Id + Username string `json:"username"` // Username + IsEmailVerified int `json:"is_email_verified"` // IsEmailVerified + Email string `json:"email"` // Email + Password string `json:"password"` // Password + PasswordHash string `json:"password_hash"` // PasswordHash + Avatar string `json:"avatar"` // Avatar + Role string `json:"role"` // Role + Status int `json:"status"` // Status + LastSpace int `json:"last_space"` // LastSpace + CreatedAt time.Time `json:"created_at"` // CreatedAt + UpdatedAt time.Time `json:"updated_at"` // UpdatedAt +} + +func (u *User) TableName() string { + return "users" +} diff --git a/service/member/internal/server/grpc.go b/service/member/internal/server/grpc.go new file mode 100644 index 0000000..34be647 --- /dev/null +++ b/service/member/internal/server/grpc.go @@ -0,0 +1,38 @@ +package server + +import ( + "fmt" + "github.com/asim/go-micro/plugins/registry/consul/v4" + "github.com/asim/go-micro/plugins/server/grpc/v4" + "go-micro.dev/v4" + "go-micro.dev/v4/registry" + "go-micro.dev/v4/server" + "gomicro-base/api/member" + "gomicro-base/service/member/internal/conf" + "gomicro-base/service/member/internal/service" + "time" +) + +func NewMicroServer(conf *conf.Config, svc *service.MemberService) micro.Service { + reg := consul.NewRegistry(registry.Addrs(conf.Server.ConsulServer...)) + //reg := etcd.NewRegistry(registry.Addrs(conf.Server.EtcdServer...)) + opt := []micro.Option{ + micro.Server(grpc.NewServer()), + micro.Name(conf.Server.Name), + micro.Address(conf.Server.Grpc.Addr), + micro.Registry(reg), + micro.RegisterTTL(time.Second * 30), + micro.RegisterInterval(time.Second * 10), + } + s := micro.NewService(opt...) + s.Server().Init(server.Wait(nil)) + + //reflection.Register() + s.Init() + + err := member.RegisterMemberHandler(s.Server(), &handler{svc: svc}) + if err != nil { + fmt.Println(err) + } + return s +} diff --git a/service/member/internal/server/handler.go b/service/member/internal/server/handler.go new file mode 100644 index 0000000..066a554 --- /dev/null +++ b/service/member/internal/server/handler.go @@ -0,0 +1,47 @@ +package server + +import ( + "context" + "gomicro-base/api/member" + "gomicro-base/common/errorm" + "gomicro-base/common/hashutil" + "gomicro-base/common/validate" + "gomicro-base/service/member/internal/model" + "gomicro-base/service/member/internal/service" + "gorm.io/gorm" +) + +// 检查接口实现 +var _ member.MemberHandler = &handler{} + +type handler struct { + svc *service.MemberService +} + +func (h *handler) GetMemberInfo(ctx context.Context, req *member.MemberInfoReq, resp *member.MemberInfoResp) error { + err := validate.Struct(req) + if err != nil { + return errorm.TransParamsError(err) + } + + m, err := h.svc.GetMemberInfo(ctx, req) + if err != nil { + if err == gorm.ErrRecordNotFound { + return errorm.NotFound(err.Error()) + } + return err + } + *resp = *h.convertMemberModel(m) + return nil +} + +func (h *handler) convertMemberModel(m *model.ImsDbPlayMember) (resp *member.MemberInfoResp) { + return &member.MemberInfoResp{ + UserId: int64(m.Id), + UserNo: int64(m.UserNo), + Avatar: hashutil.Base64Decode(m.Nickname), + Coins: int64(m.Credit1), + CoinIcon: "https://image.whoisamy.shop/attachment/2022/02/15/ca8515b15ad91375537e4c6b67dbfbbbdb30c95b.png", + RoomId: "10001", + } +} diff --git a/service/member/internal/service/service.go b/service/member/internal/service/service.go new file mode 100644 index 0000000..4484dff --- /dev/null +++ b/service/member/internal/service/service.go @@ -0,0 +1,27 @@ +package service + +import ( + "context" + "gomicro-base/api/member" + "gomicro-base/service/member/internal/dao" + "gomicro-base/service/member/internal/model" +) + +// MemberService 服务层处理逻辑 +type MemberService struct { + dao *dao.Dao +} + +func New(d *dao.Dao) *MemberService { + return &MemberService{ + dao: d, + } +} + +func (s *MemberService) GetMemberInfo(ctx context.Context, req *member.MemberInfoReq) (*model.ImsDbPlayMember, error) { + m, err := s.dao.GetMemberById(int(req.UserId), req.Token, []string{"*"}) + if err != nil { + return nil, err + } + return m, err +} diff --git a/service/member/main.go b/service/member/main.go new file mode 100644 index 0000000..3af35ab --- /dev/null +++ b/service/member/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "flag" + "fmt" + "go-micro.dev/v4/logger" + "golang.org/x/sync/errgroup" + "gomicro-base/common/logz" + "gomicro-base/service/member/internal/conf" + "gomicro-base/service/member/internal/dao" + "gomicro-base/service/member/internal/server" + "gomicro-base/service/member/internal/service" + "os" + "os/signal" + "syscall" +) + +func main() { + flag.Parse() + + conf.LoadConfig() + + if conf.Conf.Server.Name == "" { + panic("服务名不能为空") + } + + // github.com/go-micro/plugins/v4/logger/zap + logger.DefaultLogger = logz.NewLogger(conf.Conf.Log) + defer logz.Flush() + + svc := service.New(dao.New(conf.Conf)) + microServer := server.NewMicroServer(conf.Conf, svc) + + eg := errgroup.Group{} + eg.Go(func() error { + return microServer.Run() + }) + + eg.Go(func() error { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + v := <-ch + fmt.Println() + logz.Warnf("捕获退出信号: %v", v) + return nil + }) + + if err := eg.Wait(); err != nil { + logz.Error(err) + } + +} diff --git a/service/wallet/.air.toml b/service/wallet/.air.toml new file mode 100644 index 0000000..89b070d --- /dev/null +++ b/service/wallet/.air.toml @@ -0,0 +1,37 @@ +# air热更新https://github.com/cosmtrek/air 或者 使用go-micro +root = "." +testdata_dir = "testdata" +tmp_dir = "bin" + +[build] +bin = "./bin/server" +cmd = "go build -o ./bin/server ." +delay = 100 +exclude_dir = ["assets", "tmp", "vendor", "testdata"] +exclude_file = [] +exclude_regex = ["_test.go"] +exclude_unchanged = false +follow_symlink = false +full_bin = "" +include_dir = [] +include_ext = ["go", "tpl", "tmpl", "html"] +kill_delay = 100 +log = "build-errors.log" +send_interrupt = true +stop_on_error = true + +[color] +app = "" +build = "yellow" +main = "magenta" +runner = "green" +watcher = "cyan" + +[log] +time = true + +[misc] +clean_on_exit = false + +[screen] +clear_on_rebuild = false diff --git a/service/wallet/.gitignore b/service/wallet/.gitignore new file mode 100644 index 0000000..cd38e0a --- /dev/null +++ b/service/wallet/.gitignore @@ -0,0 +1,4 @@ +tmp +temp +bin +*.log \ No newline at end of file diff --git a/service/wallet/client/client.go b/service/wallet/client/client.go new file mode 100644 index 0000000..d573270 --- /dev/null +++ b/service/wallet/client/client.go @@ -0,0 +1,42 @@ +package client + +import ( + "github.com/asim/go-micro/plugins/client/grpc/v4" + "github.com/asim/go-micro/plugins/registry/consul/v4" + "go-micro.dev/v4" + "go-micro.dev/v4/client" + "go-micro.dev/v4/registry" + "go-micro.dev/v4/selector" + "gomicro-base/service/wallet/internal/conf" +) + +var ( + microClient client.Client + cf *conf.Config +) + +func NewMicroClient(c *conf.Config) { + cf = c + microRegistry := consul.NewRegistry(registry.Addrs(c.Server.ConsulServer...)) + // 轮询访问 + newSelector := selector.NewSelector( + selector.Registry(microRegistry), + selector.SetStrategy(selector.RoundRobin), + ) + + service := micro.NewService( + micro.Client(grpc.NewClient()), + micro.Selector(newSelector), + micro.WrapClient(NewTimeoutWrapper), + //micro.WrapClient(NewLogWrapper), + ) + microClient = service.Client() +} + +func GetClient() client.Client { + return microClient +} + +func Reconnect() { + NewMicroClient(cf) +} diff --git a/service/wallet/client/middleware.go b/service/wallet/client/middleware.go new file mode 100644 index 0000000..34213be --- /dev/null +++ b/service/wallet/client/middleware.go @@ -0,0 +1,21 @@ +package client + +import ( + "context" + "go-micro.dev/v4/client" + "time" +) + +type timeoutWrapper struct { + client.Client +} + +func NewTimeoutWrapper(c client.Client) client.Client { + return &timeoutWrapper{c} +} + +func (t *timeoutWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { + timeoutCtx, cancel := context.WithTimeout(ctx, time.Second*2) + defer cancel() + return t.Client.Call(timeoutCtx, req, rsp, opts...) +} diff --git a/service/wallet/config/config.yaml b/service/wallet/config/config.yaml new file mode 100644 index 0000000..b4c9d6c --- /dev/null +++ b/service/wallet/config/config.yaml @@ -0,0 +1,28 @@ +Server: + Name: "service.wallet" + ConsulServer: + - 192.168.233.1:8500 + Grpc: + Addr: "" # 为空随机端口, 使用注册中心服务发现 + Http: + Addr: "" + +Client: + MemberName: "service.member" + +Mysql: + Dsn: remote:admin666@tcp(127.0.0.1:3306)/test?loc=Local&charset=utf8mb4&writeTimeout=3s&readTimeout=3s&timeout=1s&parseTime=true + MaxConn: 8 + MaxIdleConn: 2 + MaxLifetime: 1800 # 连接有效时间,单位秒 + Debug: true + +Redis: + Addr: 127.0.0.1:6379 + Password: "" + DB: 15 + +Log: + Color: true + Level: DEBUG + diff --git a/service/wallet/internal/conf/conf.go b/service/wallet/internal/conf/conf.go new file mode 100644 index 0000000..77af8e7 --- /dev/null +++ b/service/wallet/internal/conf/conf.go @@ -0,0 +1,44 @@ +package conf + +import ( + "flag" + "gomicro-base/common/conf" + "gomicro-base/common/logz" + "gomicro-base/common/mysql" +) + +func init() { + flag.StringVar(&confPath, "conf", "config/config.yaml", "配置文件路径") +} + +var ( + confPath string + Conf = &Config{} +) + +type Config struct { + Server *Server + Client *Client + Mysql *mysql.Config + Log *logz.Config +} + +type Server struct { + Name string + ConsulServer []string + EtcdServer []string + Grpc struct { + Addr string + } + Http struct { + Addr string + } +} + +type Client struct { + MemberName string +} + +func LoadConfig() { + conf.LoadFromYaml(confPath, &Conf) +} diff --git a/service/wallet/internal/dao/dao.go b/service/wallet/internal/dao/dao.go new file mode 100644 index 0000000..528200a --- /dev/null +++ b/service/wallet/internal/dao/dao.go @@ -0,0 +1,39 @@ +package dao + +import ( + "gomicro-base/common/mysql" + "gomicro-base/service/wallet/internal/conf" + "gomicro-base/service/wallet/internal/model" + "gorm.io/gorm" +) + +// Dao 查询数据库 +type Dao struct { + DB *gorm.DB +} + +func New(c *conf.Config) (d *Dao) { + d = &Dao{ + DB: mysql.NewDB(c.Mysql), + } + return +} + +// GetUserById 根据id查询用户 +func (d *Dao) GetUserById(id int, column []string) (res *model.User, err error) { + res = &model.User{} + err = d.DB.Model(&model.User{}). + Select(column). + Where("id = ?", id).Take(res).Error + return +} + +// ListUserGtId 查询大于该id的用户列表 +func (d *Dao) ListUserGtId(id int, limit int) (res []*model.User, err error) { + res = make([]*model.User, 0) + err = d.DB.Model(&model.User{}). + Where("id > ?", id). + Limit(limit).Order("id desc"). + Find(&res).Error + return +} diff --git a/service/wallet/internal/model/users.go b/service/wallet/internal/model/users.go new file mode 100644 index 0000000..af75b4a --- /dev/null +++ b/service/wallet/internal/model/users.go @@ -0,0 +1,24 @@ +package model + +import ( + "time" +) + +type User struct { + Id int `json:"id"` // Id + Username string `json:"username"` // Username + IsEmailVerified int `json:"is_email_verified"` // IsEmailVerified + Email string `json:"email"` // Email + Password string `json:"password"` // Password + PasswordHash string `json:"password_hash"` // PasswordHash + Avatar string `json:"avatar"` // Avatar + Role string `json:"role"` // Role + Status int `json:"status"` // Status + LastSpace int `json:"last_space"` // LastSpace + CreatedAt time.Time `json:"created_at"` // CreatedAt + UpdatedAt time.Time `json:"updated_at"` // UpdatedAt +} + +func (u *User) TableName() string { + return "users" +} diff --git a/service/wallet/internal/server/grpc.go b/service/wallet/internal/server/grpc.go new file mode 100644 index 0000000..c44e0d9 --- /dev/null +++ b/service/wallet/internal/server/grpc.go @@ -0,0 +1,38 @@ +package server + +import ( + "fmt" + "github.com/asim/go-micro/plugins/registry/consul/v4" + "github.com/asim/go-micro/plugins/server/grpc/v4" + "go-micro.dev/v4" + "go-micro.dev/v4/registry" + "go-micro.dev/v4/server" + "gomicro-base/api/wallet" + "gomicro-base/service/wallet/internal/conf" + "gomicro-base/service/wallet/internal/service" + "time" +) + +func NewMicroServer(conf *conf.Config, svc *service.WalletService) micro.Service { + reg := consul.NewRegistry(registry.Addrs(conf.Server.ConsulServer...)) + //reg := etcd.NewRegistry(registry.Addrs(conf.Server.EtcdServer...)) + opt := []micro.Option{ + micro.Server(grpc.NewServer()), + micro.Name(conf.Server.Name), + micro.Address(conf.Server.Grpc.Addr), + micro.Registry(reg), + micro.RegisterTTL(time.Second * 30), + micro.RegisterInterval(time.Second * 10), + } + s := micro.NewService(opt...) + s.Server().Init(server.Wait(nil)) + + //reflection.Register() + s.Init() + + err := wallet.RegisterWalletHandler(s.Server(), &handler{svc: svc}) + if err != nil { + fmt.Println(err) + } + return s +} diff --git a/service/wallet/internal/server/handler.go b/service/wallet/internal/server/handler.go new file mode 100644 index 0000000..8a97c81 --- /dev/null +++ b/service/wallet/internal/server/handler.go @@ -0,0 +1,60 @@ +package server + +import ( + "context" + "github.com/spf13/cast" + "gomicro-base/api/wallet" + "gomicro-base/service/wallet/internal/model" + "gomicro-base/service/wallet/internal/service" + "google.golang.org/protobuf/types/known/timestamppb" +) + +// 检查接口实现 +var _ wallet.WalletHandler = &handler{} + +// handler类似控制器 +type handler struct { + svc *service.WalletService +} + +func (h *handler) GetWallet(ctx context.Context, req *wallet.WalletReq, resp *wallet.WalletResp) error { + getWallet, err := h.svc.GetWallet(ctx, req) + if err != nil { + return err + } + *resp = *h.convertUserModel(getWallet) + return nil +} + +func (h *handler) ListWallet(ctx context.Context, req *wallet.ListWalletReq, resp *wallet.ListWalletResp) error { + if req.Limit <= 0 { + req.Limit = 15 + } + + listWallet, err := h.svc.ListWallet(ctx, req) + if err != nil { + return err + } + + list := make([]*wallet.WalletResp, 0) + for _, v := range listWallet { + c := *h.convertUserModel(v) + list = append(list, &c) + } + resp.List = list + resp.Limit = req.Limit + return nil +} + +func (h *handler) convertUserModel(users *model.User) (resp *wallet.WalletResp) { + r := &wallet.WalletResp{ + Id: cast.ToString(users.Id), + Username: users.Username, + Email: users.Email, + Avatar: users.Avatar, + Status: int32(users.Status), + CreatedAt: timestamppb.New(users.CreatedAt), + UpdatedAt: timestamppb.New(users.UpdatedAt), + } + return r +} diff --git a/service/wallet/internal/service/service.go b/service/wallet/internal/service/service.go new file mode 100644 index 0000000..bf65145 --- /dev/null +++ b/service/wallet/internal/service/service.go @@ -0,0 +1,52 @@ +package service + +import ( + "context" + "github.com/spf13/cast" + "gomicro-base/api/member" + "gomicro-base/api/wallet" + "gomicro-base/common/logz" + "gomicro-base/service/wallet/client" + "gomicro-base/service/wallet/internal/conf" + "gomicro-base/service/wallet/internal/dao" + "gomicro-base/service/wallet/internal/model" +) + +// WalletService 服务层处理逻辑 +type WalletService struct { + dao *dao.Dao +} + +func New(d *dao.Dao) *WalletService { + return &WalletService{ + dao: d, + } +} + +func (s *WalletService) GetWallet(ctx context.Context, req *wallet.WalletReq) (*model.User, error) { + getClient := client.GetClient() + service := member.NewMemberService(conf.Conf.Client.MemberName, getClient) + info, err := service.GetMemberInfo(ctx, &member.MemberInfoReq{ + UserId: 100027, + Token: "WErvu0OLJZ3Mq6dTw8HhQ4bnNsReIoFK", + }) + if err != nil { + return nil, err + } + + logz.Println(info) + + user, err := s.dao.GetUserById(cast.ToInt(req.Id), []string{"*"}) + if err != nil { + return nil, err + } + return user, err +} + +func (s *WalletService) ListWallet(ctx context.Context, req *wallet.ListWalletReq) ([]*model.User, error) { + list, err := s.dao.ListUserGtId(cast.ToInt(req.Id), int(req.Limit)) + if err != nil { + return nil, err + } + return list, nil +} diff --git a/service/wallet/main.go b/service/wallet/main.go new file mode 100644 index 0000000..7d9f3a5 --- /dev/null +++ b/service/wallet/main.go @@ -0,0 +1,55 @@ +package main + +import ( + "flag" + "fmt" + "go-micro.dev/v4/logger" + "golang.org/x/sync/errgroup" + "gomicro-base/common/logz" + "gomicro-base/service/wallet/client" + "gomicro-base/service/wallet/internal/conf" + "gomicro-base/service/wallet/internal/dao" + "gomicro-base/service/wallet/internal/server" + "gomicro-base/service/wallet/internal/service" + "os" + "os/signal" + "syscall" +) + +func main() { + flag.Parse() + + conf.LoadConfig() + + if conf.Conf.Server.Name == "" { + panic("服务名不能为空") + } + + // github.com/go-micro/plugins/v4/logger/zap + logger.DefaultLogger = logz.NewLogger(conf.Conf.Log) + defer logz.Flush() + + svc := service.New(dao.New(conf.Conf)) + microServer := server.NewMicroServer(conf.Conf, svc) + + client.NewMicroClient(conf.Conf) + + eg := errgroup.Group{} + eg.Go(func() error { + return microServer.Run() + }) + + eg.Go(func() error { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + v := <-ch + fmt.Println() + logz.Warnf("捕获退出信号: %v", v) + return nil + }) + + if err := eg.Wait(); err != nil { + logz.Error(err) + } + +} -- 2.22.0