fix: 修复各种错误,日志配置为文件

main
NorthLan 3 years ago
parent 121988bfe1
commit 99e4167c96

@ -1,7 +1,7 @@
Name: gift.rpc Name: gift.rpc
ListenOn: 127.0.0.1:10000 ListenOn: 127.0.0.1:10002
DB: DB:
DataSource: root:root@tcp(192.168.1.100:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true DataSource: root:root@tcp(127.0.0.1:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true
Etcd: Etcd:
Hosts: Hosts:
- 127.0.0.1:2379 - 127.0.0.1:2379
@ -11,3 +11,7 @@ Gift:
Addr: [ "127.0.0.1:9093" ] Addr: [ "127.0.0.1:9093" ]
Topic: "gift" Topic: "gift"
ConsumerGroupId: "msgToDb" ConsumerGroupId: "msgToDb"
Log:
Mode: file
KeepDays: 7
Level: error

@ -1,6 +1,9 @@
package config package config
import "github.com/zeromicro/go-zero/zrpc" import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/zrpc"
)
type ( type (
Kafka struct { Kafka struct {
@ -10,7 +13,7 @@ type (
} }
Config struct { Config struct {
zrpc.RpcServerConf zrpc.RpcServerConf
Log logx.LogConf
DB struct { DB struct {
DataSource string DataSource string
} }

@ -5,6 +5,7 @@ import (
"git.noahlan.cn/northlan/ntools-go/uuid" "git.noahlan.cn/northlan/ntools-go/uuid"
"github.com/pkg/errors" "github.com/pkg/errors"
"live-service/app/gift/model" "live-service/app/gift/model"
"strconv"
"live-service/app/gift/rpc/internal/svc" "live-service/app/gift/rpc/internal/svc"
"live-service/app/gift/rpc/pb" "live-service/app/gift/rpc/pb"
@ -28,7 +29,8 @@ func NewCollectGiftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Colle
// CollectGift 收集礼物,仅作为收集使用 // CollectGift 收集礼物,仅作为收集使用
func (l *CollectGiftLogic) CollectGift(in *pb.CollectGift) (*pb.Empty, error) { func (l *CollectGiftLogic) CollectGift(in *pb.CollectGift) (*pb.Empty, error) {
dbGift, err := l.svcCtx.GiftModel.FindOneByGiftId(l.ctx, string(in.GiftId)) giftIdStr := strconv.FormatInt(in.GiftId, 10)
dbGift, err := l.svcCtx.GiftModel.FindOneByGiftId(l.ctx, giftIdStr)
if err == nil { if err == nil {
return &pb.Empty{}, nil return &pb.Empty{}, nil
} }
@ -39,7 +41,7 @@ func (l *CollectGiftLogic) CollectGift(in *pb.CollectGift) (*pb.Empty, error) {
} }
dbGift = &model.Gift{ dbGift = &model.Gift{
Id: uuid.NextId(), Id: uuid.NextId(),
GiftId: string(in.GiftId), GiftId: giftIdStr,
GiftName: in.GiftName, GiftName: in.GiftName,
Platform: in.Platform, Platform: in.Platform,
PPrice: in.TotalCoin, PPrice: in.TotalCoin,

@ -11,6 +11,7 @@ import (
"live-service/app/gift/rpc/pb" "live-service/app/gift/rpc/pb"
pbMq "live-service/app/pb/mq" pbMq "live-service/app/pb/mq"
kfk "live-service/common/kafka" kfk "live-service/common/kafka"
"sync"
) )
type msgHandlerFunc func(data []byte, msgKey string) type msgHandlerFunc func(data []byte, msgKey string)
@ -24,6 +25,7 @@ type MsgToDBHandler struct {
ConsumerGroup *kafka.ConsumerGroup ConsumerGroup *kafka.ConsumerGroup
mutex sync.Mutex
logx.Logger logx.Logger
} }
@ -57,6 +59,8 @@ func (h *MsgToDBHandler) handleGift(data []byte, msgKey string) {
h.Logger.Error("unmarshal msg err", err) h.Logger.Error("unmarshal msg err", err)
return return
} }
h.mutex.Lock()
defer h.mutex.Unlock()
if _, err := h.svr.CollectGift(context.Background(), &pb.CollectGift{ if _, err := h.svr.CollectGift(context.Background(), &pb.CollectGift{
Platform: msgFromMq.Platform, Platform: msgFromMq.Platform,
GiftId: msgFromMq.GiftId, GiftId: msgFromMq.GiftId,

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.28.0 // protoc-gen-go v1.27.1
// protoc v3.19.4 // protoc v3.19.4
// source: gift.proto // source: gift.proto
@ -27,7 +27,7 @@ type CollectGift struct {
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,omitempty"` Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,omitempty"`
GiftId int32 `protobuf:"varint,2,opt,name=giftId,proto3" json:"giftId,omitempty"` GiftId int64 `protobuf:"varint,2,opt,name=giftId,proto3" json:"giftId,omitempty"`
GiftName string `protobuf:"bytes,3,opt,name=giftName,proto3" json:"giftName,omitempty"` GiftName string `protobuf:"bytes,3,opt,name=giftName,proto3" json:"giftName,omitempty"`
TotalCoin int64 `protobuf:"varint,4,opt,name=totalCoin,proto3" json:"totalCoin,omitempty"` TotalCoin int64 `protobuf:"varint,4,opt,name=totalCoin,proto3" json:"totalCoin,omitempty"`
} }
@ -71,7 +71,7 @@ func (x *CollectGift) GetPlatform() string {
return "" return ""
} }
func (x *CollectGift) GetGiftId() int32 { func (x *CollectGift) GetGiftId() int64 {
if x != nil { if x != nil {
return x.GiftId return x.GiftId
} }
@ -137,7 +137,7 @@ var file_gift_proto_rawDesc = []byte{
0x22, 0x7b, 0x0a, 0x0b, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x47, 0x69, 0x66, 0x74, 0x12, 0x22, 0x7b, 0x0a, 0x0b, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x47, 0x69, 0x66, 0x74, 0x12,
0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x67,
0x69, 0x66, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x67, 0x69, 0x66, 0x69, 0x66, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, 0x69, 0x66,
0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12,
0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x18, 0x04, 0x20, 0x01,

@ -7,14 +7,13 @@ option go_package = "./pb";
// req // req
message CollectGift { message CollectGift {
string platform = 1; string platform = 1;
int32 giftId = 2; int64 giftId = 2;
string giftName = 3; string giftName = 3;
int64 totalCoin = 4; int64 totalCoin = 4;
} }
message Empty {} message Empty {}
service gift { service gift {
// collectGift ,使 // collectGift ,使
rpc collectGift(CollectGift) returns (Empty); rpc collectGift(CollectGift) returns (Empty);

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.28.0 // protoc-gen-go v1.27.1
// protoc v3.19.4 // protoc v3.19.4
// source: mq.proto // source: mq.proto
@ -168,7 +168,7 @@ type MqGift struct {
LiveRoomId int64 `protobuf:"varint,2,opt,name=liveRoomId,proto3" json:"liveRoomId,omitempty"` LiveRoomId int64 `protobuf:"varint,2,opt,name=liveRoomId,proto3" json:"liveRoomId,omitempty"`
Uid int64 `protobuf:"varint,3,opt,name=uid,proto3" json:"uid,omitempty"` Uid int64 `protobuf:"varint,3,opt,name=uid,proto3" json:"uid,omitempty"`
Uname string `protobuf:"bytes,4,opt,name=uname,proto3" json:"uname,omitempty"` Uname string `protobuf:"bytes,4,opt,name=uname,proto3" json:"uname,omitempty"`
GiftId int32 `protobuf:"varint,5,opt,name=giftId,proto3" json:"giftId,omitempty"` GiftId int64 `protobuf:"varint,5,opt,name=giftId,proto3" json:"giftId,omitempty"`
GiftName string `protobuf:"bytes,6,opt,name=giftName,proto3" json:"giftName,omitempty"` GiftName string `protobuf:"bytes,6,opt,name=giftName,proto3" json:"giftName,omitempty"`
TotalCoin int64 `protobuf:"varint,7,opt,name=totalCoin,proto3" json:"totalCoin,omitempty"` TotalCoin int64 `protobuf:"varint,7,opt,name=totalCoin,proto3" json:"totalCoin,omitempty"`
SendTime int64 `protobuf:"varint,8,opt,name=sendTime,proto3" json:"sendTime,omitempty"` SendTime int64 `protobuf:"varint,8,opt,name=sendTime,proto3" json:"sendTime,omitempty"`
@ -234,7 +234,7 @@ func (x *MqGift) GetUname() string {
return "" return ""
} }
func (x *MqGift) GetGiftId() int32 { func (x *MqGift) GetGiftId() int64 {
if x != nil { if x != nil {
return x.GiftId return x.GiftId
} }
@ -284,7 +284,7 @@ var file_mq_proto_rawDesc = []byte{
0x03, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x03, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12,
0x14, 0x0a, 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x14, 0x0a, 0x05, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
0x75, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x18, 0x75, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x18,
0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a,
0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52,
0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74,
0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x6f, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x6f,

@ -25,7 +25,7 @@ message MqGift {
int64 liveRoomId = 2; int64 liveRoomId = 2;
int64 uid = 3; int64 uid = 3;
string uname = 4; string uname = 4;
int32 giftId = 5; int64 giftId = 5;
string giftName = 6; string giftName = 6;
int64 totalCoin = 7; int64 totalCoin = 7;
int64 sendTime = 8; int64 sendTime = 8;

@ -5,7 +5,7 @@ Etcd:
- 127.0.0.1:2379 - 127.0.0.1:2379
Key: usercenter.rpc Key: usercenter.rpc
DB: DB:
DataSource: root:root@tcp(192.168.1.100:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true DataSource: root:root@tcp(127.0.0.1:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true
Danmaku: Danmaku:
Kafka: Kafka:
Addr: [ "127.0.0.1:9093" ] Addr: [ "127.0.0.1:9093" ]
@ -15,3 +15,7 @@ Danmaku:
Keys: [ "j","J","加入","加入游戏" ] Keys: [ "j","J","加入","加入游戏" ]
User: User:
UpdateDuration: 72 # 72 hours UpdateDuration: 72 # 72 hours
Log:
Mode: file
KeepDays: 7
Level: error

@ -1,6 +1,9 @@
package config package config
import "github.com/zeromicro/go-zero/zrpc" import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/zrpc"
)
type ( type (
Kafka struct { Kafka struct {
@ -10,7 +13,7 @@ type (
} }
Config struct { Config struct {
zrpc.RpcServerConf zrpc.RpcServerConf
Log logx.LogConf
DB struct { DB struct {
DataSource string DataSource string
} }

@ -2,7 +2,7 @@ package platform_user
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
pbMq "live-service/app/user_center/pb/mq" pbMq "live-service/app/pb/mq"
) )
// PlatformUser 仅提取需要的部分,其余的json后装到p_info // PlatformUser 仅提取需要的部分,其余的json后装到p_info

@ -1,6 +1,6 @@
package danmaku package danmaku
import pbMq "live-service/app/user_center/pb/mq" import pbMq "live-service/app/pb/mq"
type HandlerFunc func(roomId int64, cmd string, dm *pbMq.MqDanmaku) type HandlerFunc func(roomId int64, cmd string, dm *pbMq.MqDanmaku)

@ -6,12 +6,13 @@ import (
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
pbMq "live-service/app/user_center/pb/mq" pbMq "live-service/app/pb/mq"
"live-service/app/user_center/rpc/internal/server" "live-service/app/user_center/rpc/internal/server"
"live-service/app/user_center/rpc/internal/svc" "live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb" "live-service/app/user_center/rpc/pb"
kfk "live-service/common/kafka" kfk "live-service/common/kafka"
"strconv" "strconv"
"sync"
) )
type msgHandlerFunc func(data []byte, msgKey string) type msgHandlerFunc func(data []byte, msgKey string)
@ -28,6 +29,7 @@ type MsgToDBHandler struct {
ConsumerGroup *kafka.ConsumerGroup ConsumerGroup *kafka.ConsumerGroup
mutex sync.Mutex
logx.Logger logx.Logger
} }
@ -60,6 +62,8 @@ func (h *MsgToDBHandler) Init(context context.Context, ctx *svc.ServiceContext,
} }
func (h *MsgToDBHandler) handleJoinGame(_ int64, _ string, danmaku *pbMq.MqDanmaku) { func (h *MsgToDBHandler) handleJoinGame(_ int64, _ string, danmaku *pbMq.MqDanmaku) {
h.mutex.Lock()
defer h.mutex.Unlock()
_, err := h.svr.RetrievePlatformUser(h.context, &pb.PlatformUserReq{ _, err := h.svr.RetrievePlatformUser(h.context, &pb.PlatformUserReq{
Platform: danmaku.Platform, Platform: danmaku.Platform,
PUid: strconv.FormatInt(danmaku.Uid, 10), PUid: strconv.FormatInt(danmaku.Uid, 10),

Loading…
Cancel
Save