feat: gorm

main
NorthLan 3 years ago
parent 1417e654a4
commit 9a4978e1e9

@ -1,20 +0,0 @@
@echo off
@echo ??????????????
set tables=gift
set targetDir=.\model
set templateDir=..\..\doc\template
::set host=127.0.0.1
::set port=23306
set host=192.168.1.100
set port=3306
::set dbname=dcg
set dbname=dmgame
set username=root
set password=root
for %%i in (%tables%) do (
echo ????????? %dbname% ??? %%i
goctl model mysql datasource --url "%username%:%password%@tcp(%host%:%port%)/%dbname%" -t %%i -d %targetDir% --style go_zero --home %templateDir%
)

@ -1,12 +0,0 @@
package user_center
// protoc 生成
//go:generate goctl rpc protoc ./rpc/pb/gift.proto --style=go_zero --go_out=./rpc --go-grpc_out=./rpc --zrpc_out=./rpc
// api 生成
//go:generate goctl api go -api ./api/doc/user_center.api -dir ./api --style go_zero
// api swagger 文档生成 需要sh
//go:generate goctl api plugin -plugin goctl-swagger="swagger -filename user_center.json -host 127.0.0.1" -api ./api/doc/user_center.api -dir ./api/doc
// model 生成 配合genModel.sh (可能需要复制到terminal执行)

@ -1,44 +0,0 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ GiftModel = (*customGiftModel)(nil)
type (
// GiftModel is an interface to be customized, add more methods here,
// and implement the added methods in customGiftModel.
GiftModel interface {
giftModel
FindOneByGiftId(ctx context.Context, giftId string) (*Gift, error)
}
customGiftModel struct {
*defaultGiftModel
}
)
// NewGiftModel returns a model for the database table.
func NewGiftModel(conn sqlx.SqlConn) GiftModel {
return &customGiftModel{
defaultGiftModel: newGiftModel(conn),
}
}
func (m *customGiftModel) FindOneByGiftId(ctx context.Context, giftId string) (*Gift, error) {
query := fmt.Sprintf("select %s from %s where `gift_id` = ? limit 1", giftRows, m.table)
var resp Gift
err := m.conn.QueryRowCtx(ctx, &resp, query, giftId)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}

@ -1,87 +0,0 @@
// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
giftFieldNames = builder.RawFieldNames(&Gift{})
giftRows = strings.Join(giftFieldNames, ",")
giftRowsExpectAutoSet = strings.Join(stringx.Remove(giftFieldNames, "`create_time`", "`update_time`"), ",")
giftRowsWithPlaceHolder = strings.Join(stringx.Remove(giftFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
)
type (
giftModel interface {
Insert(ctx context.Context, data *Gift) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*Gift, error)
Update(ctx context.Context, data *Gift) error
Delete(ctx context.Context, id int64) error
}
defaultGiftModel struct {
conn sqlx.SqlConn
table string
}
Gift struct {
Id int64 `db:"id"` // 主键
GiftId string `db:"gift_id"` // 礼物ID不同平台可能类型都不同用varchar
GiftName string `db:"gift_name"` // 礼物名
Platform string `db:"platform"` // 平台
PPrice int64 `db:"p_price"` // 平台价值货币总数B站: 瓜子虎牙: xxx
}
)
func newGiftModel(conn sqlx.SqlConn) *defaultGiftModel {
return &defaultGiftModel{
conn: conn,
table: "`gift`",
}
}
func (m *defaultGiftModel) Insert(ctx context.Context, data *Gift) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, giftRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.GiftId, data.GiftName, data.Platform, data.PPrice)
return ret, err
}
func (m *defaultGiftModel) FindOne(ctx context.Context, id int64) (*Gift, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", giftRows, m.table)
var resp Gift
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultGiftModel) Update(ctx context.Context, data *Gift) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, giftRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.GiftId, data.GiftName, data.Platform, data.PPrice, data.Id)
return err
}
func (m *defaultGiftModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultGiftModel) tableName() string {
return m.table
}

@ -1,5 +0,0 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var ErrNotFound = sqlx.ErrNotFound

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

@ -1,45 +0,0 @@
package main
import (
"context"
"flag"
"fmt"
"live-service/app/gift/rpc/msg_transfer"
"live-service/app/gift/rpc/internal/config"
"live-service/app/gift/rpc/internal/server"
"live-service/app/gift/rpc/internal/svc"
"live-service/app/gift/rpc/pb"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/gift.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
svr := server.NewGiftServer(ctx)
msg_transfer.Init(context.Background(), ctx, svr)
msg_transfer.Run()
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
pb.RegisterGiftServer(grpcServer, svr)
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}

@ -1,39 +0,0 @@
// Code generated by goctl. DO NOT EDIT!
// Source: gift.proto
package gift
import (
"context"
"live-service/app/gift/rpc/pb"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
CollectGift = pb.CollectGift
Empty = pb.Empty
Gift interface {
// collectGift 收集礼物,仅作为收集使用
CollectGift(ctx context.Context, in *CollectGift, opts ...grpc.CallOption) (*Empty, error)
}
defaultGift struct {
cli zrpc.Client
}
)
func NewGift(cli zrpc.Client) Gift {
return &defaultGift{
cli: cli,
}
}
// collectGift 收集礼物,仅作为收集使用
func (m *defaultGift) CollectGift(ctx context.Context, in *CollectGift, opts ...grpc.CallOption) (*Empty, error) {
client := pb.NewGiftClient(m.cli.Conn())
return client.CollectGift(ctx, in, opts...)
}

@ -1,25 +0,0 @@
package config
import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/zrpc"
)
type (
Kafka struct {
Addr []string
Topic string
ConsumerGroupId string
}
Config struct {
zrpc.RpcServerConf
Log logx.LogConf
DB struct {
DataSource string
}
Gift struct {
Kafka Kafka
}
}
)

@ -1,53 +0,0 @@
package logic
import (
"context"
"git.noahlan.cn/northlan/ntools-go/uuid"
"github.com/pkg/errors"
"live-service/app/gift/model"
"strconv"
"live-service/app/gift/rpc/internal/svc"
"live-service/app/gift/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type CollectGiftLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCollectGiftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectGiftLogic {
return &CollectGiftLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// CollectGift 收集礼物,仅作为收集使用
func (l *CollectGiftLogic) CollectGift(in *pb.CollectGift) (*pb.Empty, error) {
giftIdStr := strconv.FormatInt(in.GiftId, 10)
dbGift, err := l.svcCtx.GiftModel.FindOneByGiftId(l.ctx, giftIdStr)
if err == nil {
return &pb.Empty{}, nil
}
if err != nil {
if !errors.Is(err, model.ErrNotFound) {
return nil, errors.Wrap(err, "数据库错误")
}
}
dbGift = &model.Gift{
Id: uuid.NextId(),
GiftId: giftIdStr,
GiftName: in.GiftName,
Platform: in.Platform,
PPrice: in.TotalCoin,
}
if _, err := l.svcCtx.GiftModel.Insert(l.ctx, dbGift); err != nil {
return nil, errors.Wrap(err, "数据库插入错误")
}
return &pb.Empty{}, nil
}

@ -1,29 +0,0 @@
// Code generated by goctl. DO NOT EDIT!
// Source: gift.proto
package server
import (
"context"
"live-service/app/gift/rpc/internal/logic"
"live-service/app/gift/rpc/internal/svc"
"live-service/app/gift/rpc/pb"
)
type GiftServer struct {
svcCtx *svc.ServiceContext
pb.UnimplementedGiftServer
}
func NewGiftServer(svcCtx *svc.ServiceContext) *GiftServer {
return &GiftServer{
svcCtx: svcCtx,
}
}
// collectGift 收集礼物,仅作为收集使用
func (s *GiftServer) CollectGift(ctx context.Context, in *pb.CollectGift) (*pb.Empty, error) {
l := logic.NewCollectGiftLogic(ctx, s.svcCtx)
return l.CollectGift(in)
}

@ -1,21 +0,0 @@
package svc
import (
"github.com/zeromicro/go-zero/core/stores/sqlx"
"live-service/app/gift/model"
"live-service/app/gift/rpc/internal/config"
)
type ServiceContext struct {
Config config.Config
GiftModel model.GiftModel
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
// model
GiftModel: model.NewGiftModel(sqlx.NewMysql(c.DB.DataSource)),
}
}

@ -1,85 +0,0 @@
package gift
import (
"context"
"git.noahlan.cn/northlan/ntools-go/kafka"
"github.com/Shopify/sarama"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/protobuf/proto"
"live-service/app/gift/rpc/internal/server"
"live-service/app/gift/rpc/internal/svc"
"live-service/app/gift/rpc/pb"
pbMq "live-service/app/pb/mq"
kfk "live-service/common/kafka"
"sync"
)
type msgHandlerFunc func(data []byte, msgKey string)
type MsgToDBHandler struct {
context context.Context
ctx *svc.ServiceContext
svr *server.GiftServer
msgHandle map[string]msgHandlerFunc
ConsumerGroup *kafka.ConsumerGroup
mutex sync.Mutex
logx.Logger
}
func (h *MsgToDBHandler) Init(context context.Context, ctx *svc.ServiceContext, svr *server.GiftServer) {
h.context = context
h.ctx = ctx
h.svr = svr
h.Logger = logx.WithContext(h.context)
cfg := ctx.Config.Gift.Kafka
h.msgHandle = make(map[string]msgHandlerFunc)
h.msgHandle["gift"] = h.handleGift
var err error
h.ConsumerGroup, err = kafka.NewConsumerGroup(&kafka.ConsumerGroupConfig{
KafkaVersion: sarama.V3_1_0_0,
OffsetsInitial: sarama.OffsetNewest,
IsReturnErr: false,
UnMarshaler: kfk.ProtobufMarshaler,
}, cfg.Addr, []string{cfg.Topic}, cfg.ConsumerGroupId)
if err != nil {
h.Logger.Error(err)
}
}
func (h *MsgToDBHandler) handleGift(data []byte, msgKey string) {
// msg proto
var msgFromMq pbMq.MqGift
if err := proto.Unmarshal(data, &msgFromMq); err != nil {
h.Logger.Error("unmarshal msg err", err)
return
}
h.mutex.Lock()
defer h.mutex.Unlock()
if _, err := h.svr.CollectGift(context.Background(), &pb.CollectGift{
Platform: msgFromMq.Platform,
GiftId: msgFromMq.GiftId,
GiftName: msgFromMq.GiftName,
TotalCoin: msgFromMq.TotalCoin,
}); err != nil {
h.Logger.Error("收集礼物错误 ", err)
return
}
}
func (*MsgToDBHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }
func (*MsgToDBHandler) Cleanup(_ sarama.ConsumerGroupSession) error { return nil }
func (h *MsgToDBHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
for msg := range claim.Messages() {
if hFunc, ok := h.msgHandle[msg.Topic]; ok {
hFunc(msg.Value, string(msg.Key))
}
sess.MarkMessage(msg, "")
}
return nil
}

@ -1,20 +0,0 @@
package msg_transfer
import (
"context"
"live-service/app/gift/rpc/internal/server"
"live-service/app/gift/rpc/internal/svc"
"live-service/app/gift/rpc/msg_transfer/gift"
)
var (
giftMsgToDb gift.MsgToDBHandler
)
func Init(context context.Context, ctx *svc.ServiceContext, svr *server.GiftServer) {
giftMsgToDb.Init(context, ctx, svr)
}
func Run() {
go giftMsgToDb.ConsumerGroup.RegisterHandlerAndConsumer(&giftMsgToDb)
}

@ -1,3 +0,0 @@
package pb
//go:generate goctl rpc protoc gift.proto --style=go_zero --go_out=../ --go-grpc_out=../ --zrpc_out=../

@ -1,228 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.19.4
// source: gift.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
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)
)
// req
type CollectGift struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,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"`
TotalCoin int64 `protobuf:"varint,4,opt,name=totalCoin,proto3" json:"totalCoin,omitempty"`
}
func (x *CollectGift) Reset() {
*x = CollectGift{}
if protoimpl.UnsafeEnabled {
mi := &file_gift_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CollectGift) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CollectGift) ProtoMessage() {}
func (x *CollectGift) ProtoReflect() protoreflect.Message {
mi := &file_gift_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 CollectGift.ProtoReflect.Descriptor instead.
func (*CollectGift) Descriptor() ([]byte, []int) {
return file_gift_proto_rawDescGZIP(), []int{0}
}
func (x *CollectGift) GetPlatform() string {
if x != nil {
return x.Platform
}
return ""
}
func (x *CollectGift) GetGiftId() int64 {
if x != nil {
return x.GiftId
}
return 0
}
func (x *CollectGift) GetGiftName() string {
if x != nil {
return x.GiftName
}
return ""
}
func (x *CollectGift) GetTotalCoin() int64 {
if x != nil {
return x.TotalCoin
}
return 0
}
type Empty struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *Empty) Reset() {
*x = Empty{}
if protoimpl.UnsafeEnabled {
mi := &file_gift_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Empty) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Empty) ProtoMessage() {}
func (x *Empty) ProtoReflect() protoreflect.Message {
mi := &file_gift_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 Empty.ProtoReflect.Descriptor instead.
func (*Empty) Descriptor() ([]byte, []int) {
return file_gift_proto_rawDescGZIP(), []int{1}
}
var File_gift_proto protoreflect.FileDescriptor
var file_gift_proto_rawDesc = []byte{
0x0a, 0x0a, 0x67, 0x69, 0x66, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62,
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,
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, 0x03, 0x52, 0x06, 0x67, 0x69, 0x66,
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,
0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x18, 0x04, 0x20, 0x01,
0x28, 0x03, 0x52, 0x09, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x22, 0x07, 0x0a,
0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x32, 0x31, 0x0a, 0x04, 0x67, 0x69, 0x66, 0x74, 0x12, 0x29,
0x0a, 0x0b, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x47, 0x69, 0x66, 0x74, 0x12, 0x0f, 0x2e,
0x70, 0x62, 0x2e, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x47, 0x69, 0x66, 0x74, 0x1a, 0x09,
0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70,
0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_gift_proto_rawDescOnce sync.Once
file_gift_proto_rawDescData = file_gift_proto_rawDesc
)
func file_gift_proto_rawDescGZIP() []byte {
file_gift_proto_rawDescOnce.Do(func() {
file_gift_proto_rawDescData = protoimpl.X.CompressGZIP(file_gift_proto_rawDescData)
})
return file_gift_proto_rawDescData
}
var file_gift_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_gift_proto_goTypes = []interface{}{
(*CollectGift)(nil), // 0: pb.CollectGift
(*Empty)(nil), // 1: pb.Empty
}
var file_gift_proto_depIdxs = []int32{
0, // 0: pb.gift.collectGift:input_type -> pb.CollectGift
1, // 1: pb.gift.collectGift:output_type -> pb.Empty
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_gift_proto_init() }
func file_gift_proto_init() {
if File_gift_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_gift_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CollectGift); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_gift_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Empty); 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_gift_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_gift_proto_goTypes,
DependencyIndexes: file_gift_proto_depIdxs,
MessageInfos: file_gift_proto_msgTypes,
}.Build()
File_gift_proto = out.File
file_gift_proto_rawDesc = nil
file_gift_proto_goTypes = nil
file_gift_proto_depIdxs = nil
}

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

@ -1,107 +0,0 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.19.4
// source: gift.proto
package pb
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// GiftClient is the client API for Gift service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type GiftClient interface {
// collectGift 收集礼物,仅作为收集使用
CollectGift(ctx context.Context, in *CollectGift, opts ...grpc.CallOption) (*Empty, error)
}
type giftClient struct {
cc grpc.ClientConnInterface
}
func NewGiftClient(cc grpc.ClientConnInterface) GiftClient {
return &giftClient{cc}
}
func (c *giftClient) CollectGift(ctx context.Context, in *CollectGift, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/pb.gift/collectGift", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// GiftServer is the server API for Gift service.
// All implementations must embed UnimplementedGiftServer
// for forward compatibility
type GiftServer interface {
// collectGift 收集礼物,仅作为收集使用
CollectGift(context.Context, *CollectGift) (*Empty, error)
mustEmbedUnimplementedGiftServer()
}
// UnimplementedGiftServer must be embedded to have forward compatible implementations.
type UnimplementedGiftServer struct {
}
func (UnimplementedGiftServer) CollectGift(context.Context, *CollectGift) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method CollectGift not implemented")
}
func (UnimplementedGiftServer) mustEmbedUnimplementedGiftServer() {}
// UnsafeGiftServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to GiftServer will
// result in compilation errors.
type UnsafeGiftServer interface {
mustEmbedUnimplementedGiftServer()
}
func RegisterGiftServer(s grpc.ServiceRegistrar, srv GiftServer) {
s.RegisterService(&Gift_ServiceDesc, srv)
}
func _Gift_CollectGift_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CollectGift)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(GiftServer).CollectGift(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/pb.gift/collectGift",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GiftServer).CollectGift(ctx, req.(*CollectGift))
}
return interceptor(ctx, in, info, handler)
}
// Gift_ServiceDesc is the grpc.ServiceDesc for Gift service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Gift_ServiceDesc = grpc.ServiceDesc{
ServiceName: "pb.gift",
HandlerType: (*GiftServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "collectGift",
Handler: _Gift_CollectGift_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "gift.proto",
}

@ -1,6 +1,8 @@
package model package model
import "github.com/zeromicro/go-zero/core/stores/sqlx" import (
"gorm.io/gorm"
)
var _ UserModel = (*customUserModel)(nil) var _ UserModel = (*customUserModel)(nil)
@ -17,7 +19,7 @@ type (
) )
// NewUserModel returns a model for the database table. // NewUserModel returns a model for the database table.
func NewUserModel(conn sqlx.SqlConn) UserModel { func NewUserModel(conn *gorm.DB) UserModel {
return &customUserModel{ return &customUserModel{
defaultUserModel: newUserModel(conn), defaultUserModel: newUserModel(conn),
} }

@ -4,15 +4,13 @@ package model
import ( import (
"context" "context"
"database/sql" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"fmt"
"strings" "strings"
"time" "time"
"github.com/zeromicro/go-zero/core/stores/builder" "github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx" "github.com/zeromicro/go-zero/core/stringx"
"gorm.io/gorm"
) )
var ( var (
@ -24,46 +22,44 @@ var (
type ( type (
userModel interface { userModel interface {
Insert(ctx context.Context, data *User) (sql.Result, error) Insert(ctx context.Context, data *User) error
FindOne(ctx context.Context, id int64) (*User, error) FindOne(ctx context.Context, id int64) (*User, error)
Update(ctx context.Context, data *User) error Update(ctx context.Context, data *User) error
Delete(ctx context.Context, id int64) error Delete(ctx context.Context, id int64) error
} }
defaultUserModel struct { defaultUserModel struct {
conn sqlx.SqlConn conn *gorm.DB
table string table string
} }
User struct { User struct {
Id int64 `db:"id"` // 用户ID Id int64 `gorm:"column:id"` // 用户ID
Username string `db:"username"` // 用户名 Username string `gorm:"column:username"` // 用户名
CreateTime time.Time `db:"create_time"` // 创建时间 CreateTime time.Time `gorm:"column:create_time"` // 创建时间
UpdateTime time.Time `db:"update_time"` // 更新时间 UpdateTime time.Time `gorm:"column:update_time"` // 更新时间
} }
) )
func newUserModel(conn sqlx.SqlConn) *defaultUserModel { func newUserModel(conn *gorm.DB) *defaultUserModel {
return &defaultUserModel{ return &defaultUserModel{
conn: conn, conn: conn,
table: "`user`", table: "`user`",
} }
} }
func (m *defaultUserModel) Insert(ctx context.Context, data *User) (sql.Result, error) { func (m *defaultUserModel) Insert(ctx context.Context, data *User) error {
query := fmt.Sprintf("insert into %s (%s) values (?, ?)", m.table, userRowsExpectAutoSet) err := m.conn.WithContext(ctx).Save(&data).Error
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.Username) return err
return ret, err
} }
func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error) { func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRows, m.table)
var resp User var resp User
err := m.conn.QueryRowCtx(ctx, &resp, query, id) err := m.conn.WithContext(ctx).Model(&User{}).Where("`id` = ?", id).Take(&resp).Error
switch err { switch err {
case nil: case nil:
return &resp, nil return &resp, nil
case sqlc.ErrNotFound: case gormc.ErrNotFound:
return nil, ErrNotFound return nil, ErrNotFound
default: default:
return nil, err return nil, err
@ -71,17 +67,21 @@ func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error)
} }
func (m *defaultUserModel) Update(ctx context.Context, data *User) error { func (m *defaultUserModel) Update(ctx context.Context, data *User) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userRowsWithPlaceHolder) err := m.conn.WithContext(ctx).Save(data).Error
_, err := m.conn.ExecCtx(ctx, query, data.Username, data.Id)
return err return err
} }
func (m *defaultUserModel) Delete(ctx context.Context, id int64) error { func (m *defaultUserModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table) err := m.conn.WithContext(ctx).Delete(&User{}, id).Error
_, err := m.conn.ExecCtx(ctx, query, id)
return err return err
} }
func (m *defaultUserModel) tableName() string { func (m *defaultUserModel) tableName() string {
return m.table return m.table
} }
func (User) TableName() string {
model := defaultUserModel{}
return model.tableName()
}

@ -2,9 +2,8 @@ package model
import ( import (
"context" "context"
"fmt" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"github.com/zeromicro/go-zero/core/stores/sqlc" "gorm.io/gorm"
"github.com/zeromicro/go-zero/core/stores/sqlx"
) )
var _ UserPlatformModel = (*customUserPlatformModel)(nil) var _ UserPlatformModel = (*customUserPlatformModel)(nil)
@ -14,7 +13,9 @@ type (
// and implement the added methods in customUserPlatformModel. // and implement the added methods in customUserPlatformModel.
UserPlatformModel interface { UserPlatformModel interface {
userPlatformModel userPlatformModel
FindOneByPlatformAndPUid(ctx context.Context, platform string, pUid string) (*UserPlatform, error) // FindOneByPlatformAndPUid 查询平台用户
FindOneByPlatformAndPUid(ctx context.Context, platform, pUid string) (*UserPlatform, error)
FindUpdatableList(ctx context.Context, duration int64, num int64) ([]UserPlatform, error)
} }
customUserPlatformModel struct { customUserPlatformModel struct {
@ -23,20 +24,34 @@ type (
) )
// NewUserPlatformModel returns a model for the database table. // NewUserPlatformModel returns a model for the database table.
func NewUserPlatformModel(conn sqlx.SqlConn) UserPlatformModel { func NewUserPlatformModel(conn *gorm.DB) UserPlatformModel {
return &customUserPlatformModel{ return &customUserPlatformModel{
defaultUserPlatformModel: newUserPlatformModel(conn), defaultUserPlatformModel: newUserPlatformModel(conn),
} }
} }
func (c *customUserPlatformModel) FindOneByPlatformAndPUid(ctx context.Context, platform string, pUid string) (*UserPlatform, error) { func (m *customUserPlatformModel) FindOneByPlatformAndPUid(ctx context.Context, platform, pUid string) (*UserPlatform, error) {
query := fmt.Sprintf("select %s from %s where `platform` = ? and `p_uid` = ? limit 1", userPlatformRows, c.table)
var resp UserPlatform var resp UserPlatform
err := c.conn.QueryRowCtx(ctx, &resp, query, platform, pUid) err := m.conn.WithContext(ctx).Model(&UserPlatform{}).Where("`platform` = ? AND `p_uid` = ?", platform, pUid).Take(&resp).Error
switch err { switch err {
case nil: case nil:
return &resp, nil return &resp, nil
case sqlc.ErrNotFound: case gormc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *customUserPlatformModel) FindUpdatableList(ctx context.Context, duration int64, num int64) ([]UserPlatform, error) {
var resp []UserPlatform
err := m.conn.WithContext(ctx).
Where("`p_info = ? AND `update_time` < (NOW() - INTERVAL ? HOUR LIMIT ?", "{}", duration, num).
Find(&resp).Error
switch err {
case nil:
return resp, nil
case gormc.ErrNotFound:
return nil, ErrNotFound return nil, ErrNotFound
default: default:
return nil, err return nil, err

@ -4,72 +4,68 @@ package model
import ( import (
"context" "context"
"database/sql" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"fmt"
"strings" "strings"
"time" "time"
"github.com/zeromicro/go-zero/core/stores/builder" "github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx" "github.com/zeromicro/go-zero/core/stringx"
"gorm.io/gorm"
) )
var ( var (
userPlatformFieldNames = builder.RawFieldNames(&UserPlatform{}) userPlatformFieldNames = builder.RawFieldNames(&UserPlatform{})
userPlatformRows = strings.Join(userPlatformFieldNames, ",") userPlatformRows = strings.Join(userPlatformFieldNames, ",")
userPlatformRowsExpectAutoSet = strings.Join(stringx.Remove(userPlatformFieldNames, "`create_time`", "`update_time`"), ",") userPlatformRowsExpectAutoSet = strings.Join(stringx.Remove(userPlatformFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
userPlatformRowsWithPlaceHolder = strings.Join(stringx.Remove(userPlatformFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?" userPlatformRowsWithPlaceHolder = strings.Join(stringx.Remove(userPlatformFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
) )
type ( type (
userPlatformModel interface { userPlatformModel interface {
Insert(ctx context.Context, data *UserPlatform) (sql.Result, error) Insert(ctx context.Context, data *UserPlatform) error
FindOne(ctx context.Context, id int64) (*UserPlatform, error) FindOne(ctx context.Context, id int64) (*UserPlatform, error)
Update(ctx context.Context, data *UserPlatform) error Update(ctx context.Context, data *UserPlatform) error
Delete(ctx context.Context, id int64) error Delete(ctx context.Context, id int64) error
} }
defaultUserPlatformModel struct { defaultUserPlatformModel struct {
conn sqlx.SqlConn conn *gorm.DB
table string table string
} }
UserPlatform struct { UserPlatform struct {
Id int64 `db:"id"` // 主键 Id int64 `gorm:"column:id"` // 主键
UserId int64 `db:"user_id"` // 用户ID UserId int64 `gorm:"column:user_id"` // 用户ID
Platform string `db:"platform"` // 平台类型 Platform string `gorm:"column:platform"` // 平台类型
POpenid string `db:"p_openid"` // 平台用户openid POpenid string `gorm:"column:p_openid"` // 平台用户openid
PUid string `db:"p_uid"` // 平台用户uid PUid string `gorm:"column:p_uid"` // 平台用户uid
PUname string `db:"p_uname"` // 平台用户名 PUname string `gorm:"column:p_uname"` // 平台用户名
PInfo string `db:"p_info"` // 平台用户原始信息(json) PInfo string `gorm:"column:p_info"` // 平台用户原始信息(json)
PAvatar string `db:"p_avatar"` // 平台用户头像地址 PAvatar string `gorm:"column:p_avatar"` // 平台用户头像地址
CreateTime time.Time `db:"create_time"` // 创建时间 CreateTime time.Time `gorm:"column:create_time"` // 创建时间
UpdateTime time.Time `db:"update_time"` // 更新时间 UpdateTime time.Time `gorm:"column:update_time"` // 更新时间
} }
) )
func newUserPlatformModel(conn sqlx.SqlConn) *defaultUserPlatformModel { func newUserPlatformModel(conn *gorm.DB) *defaultUserPlatformModel {
return &defaultUserPlatformModel{ return &defaultUserPlatformModel{
conn: conn, conn: conn,
table: "`user_platform`", table: "`user_platform`",
} }
} }
func (m *defaultUserPlatformModel) Insert(ctx context.Context, data *UserPlatform) (sql.Result, error) { func (m *defaultUserPlatformModel) Insert(ctx context.Context, data *UserPlatform) error {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, userPlatformRowsExpectAutoSet) err := m.conn.WithContext(ctx).Save(&data).Error
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.UserId, data.Platform, data.POpenid, data.PUid, data.PUname, data.PInfo, data.PAvatar) return err
return ret, err
} }
func (m *defaultUserPlatformModel) FindOne(ctx context.Context, id int64) (*UserPlatform, error) { func (m *defaultUserPlatformModel) FindOne(ctx context.Context, id int64) (*UserPlatform, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userPlatformRows, m.table)
var resp UserPlatform var resp UserPlatform
err := m.conn.QueryRowCtx(ctx, &resp, query, id) err := m.conn.WithContext(ctx).Model(&UserPlatform{}).Where("`id` = ?", id).Take(&resp).Error
switch err { switch err {
case nil: case nil:
return &resp, nil return &resp, nil
case sqlc.ErrNotFound: case gormc.ErrNotFound:
return nil, ErrNotFound return nil, ErrNotFound
default: default:
return nil, err return nil, err
@ -77,17 +73,21 @@ func (m *defaultUserPlatformModel) FindOne(ctx context.Context, id int64) (*User
} }
func (m *defaultUserPlatformModel) Update(ctx context.Context, data *UserPlatform) error { func (m *defaultUserPlatformModel) Update(ctx context.Context, data *UserPlatform) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userPlatformRowsWithPlaceHolder) err := m.conn.WithContext(ctx).Save(data).Error
_, err := m.conn.ExecCtx(ctx, query, data.UserId, data.Platform, data.POpenid, data.PUid, data.PUname, data.PInfo, data.PAvatar, data.Id)
return err return err
} }
func (m *defaultUserPlatformModel) Delete(ctx context.Context, id int64) error { func (m *defaultUserPlatformModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table) err := m.conn.WithContext(ctx).Delete(&UserPlatform{}, id).Error
_, err := m.conn.ExecCtx(ctx, query, id)
return err return err
} }
func (m *defaultUserPlatformModel) tableName() string { func (m *defaultUserPlatformModel) tableName() string {
return m.table return m.table
} }
func (UserPlatform) TableName() string {
model := defaultUserPlatformModel{}
return model.tableName()
}

@ -1,5 +1,5 @@
package model package model
import "github.com/zeromicro/go-zero/core/stores/sqlx" import "gorm.io/gorm"
var ErrNotFound = sqlx.ErrNotFound var ErrNotFound = gorm.ErrRecordNotFound

@ -4,7 +4,9 @@ Etcd:
Hosts: Hosts:
- 127.0.0.1:2379 - 127.0.0.1:2379
Key: usercenter.rpc Key: usercenter.rpc
NonBlock: true
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 DataSource: root:root@tcp(127.0.0.1:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true
Danmaku: Danmaku:
Kafka: Kafka:
@ -12,7 +14,7 @@ Danmaku:
Topic: "danmaku" Topic: "danmaku"
ConsumerGroupId: "msgToDb" ConsumerGroupId: "msgToDb"
Command: Command:
Keys: [ "j","J","加入","加入游戏" ] Keys: [ "j", "加入","加入游戏" ]
User: User:
UpdateDuration: 72 # 72 hours UpdateDuration: 72 # 72 hours
Log: Log:

@ -1,8 +1,11 @@
package platform_user package platform_user
import ( import (
"github.com/pkg/errors" "context"
"github.com/robfig/cron/v3"
"github.com/zeromicro/go-zero/core/logx"
pbMq "live-service/app/pb/mq" pbMq "live-service/app/pb/mq"
"live-service/app/user_center/rpc/internal/svc"
) )
// PlatformUser 仅提取需要的部分,其余的json后装到p_info // PlatformUser 仅提取需要的部分,其余的json后装到p_info
@ -14,23 +17,64 @@ type (
PInfo string PInfo string
} }
UserRetriever struct { UserRetriever struct {
ctx context.Context
svcCtx *svc.ServiceContext
retrieveMapper map[string]RetrieveFunc retrieveMapper map[string]RetrieveFunc
logx.Logger
} }
) )
type RetrieveFunc func(pUid string) (*PlatformUser, error) type RetrieveFunc func(pUid string) (*PlatformUser, error)
func NewUserRetriever() *UserRetriever { func NewUserRetriever(ctx context.Context, svcCtx *svc.ServiceContext) *UserRetriever {
return &UserRetriever{ result := &UserRetriever{
ctx: ctx,
svcCtx: svcCtx,
retrieveMapper: map[string]RetrieveFunc{ retrieveMapper: map[string]RetrieveFunc{
pbMq.Platform_name[int32(pbMq.Platform_bilibili)]: RetrieveBilibili, pbMq.Platform_name[int32(pbMq.Platform_bilibili)]: RetrieveBilibili,
}, },
Logger: logx.WithContext(ctx),
} }
go result.scheduler()
return result
} }
func (r *UserRetriever) RetrieveUser(platform, pUid string) (*PlatformUser, error) { func (r *UserRetriever) retrieveUser(platform, pUid string) *PlatformUser {
if handle, ok := r.retrieveMapper[platform]; ok { if handle, ok := r.retrieveMapper[platform]; ok {
return handle(pUid) if p, err := handle(pUid); err != nil {
return p
} else {
r.Logger.Errorf("获取平台用户信息错误: err: %s\n", err.Error())
}
}
return &PlatformUser{
PUid: pUid,
PName: "",
PAvatar: "",
PInfo: "{}", // 空json
}
}
func (r *UserRetriever) scheduler() {
c := cron.New()
_, _ = c.AddFunc("@every 300ms", func() {
list, err := r.svcCtx.UserPlatformModel.FindUpdatableList(r.ctx, r.svcCtx.Config.User.UpdateDuration, 10)
if err != nil {
return
}
for _, dbModel := range list {
pUser := r.retrieveUser(dbModel.Platform, dbModel.PUid)
if pUser.PInfo == "{}" {
continue
}
dbModel.PUname = pUser.PName
dbModel.PAvatar = pUser.PAvatar
dbModel.PInfo = pUser.PInfo
_ = r.svcCtx.UserPlatformModel.Update(r.ctx, &dbModel)
} }
return nil, errors.New("没有此平台的用户数据收集器") })
c.Start()
} }

@ -6,11 +6,47 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"io" "io"
"net/http" "net/http"
"net/url"
"strconv" "strconv"
) )
type MyProxy struct {
Id int64 `json:"id"`
Ip string `json:"ip"`
Port string `json:"port"`
SchemeType int `json:"scheme_type"`
Content string `json:"content"`
}
func RetrieveBilibili(pUid string) (*PlatformUser, error) { func RetrieveBilibili(pUid string) (*PlatformUser, error) {
httpResponse, err := http.Get(fmt.Sprintf("https://api.bilibili.com/x/space/acc/info?mid=%s", pUid)) proxy := func(_ *http.Request) (*url.URL, error) {
httpResponse, err := http.Get(fmt.Sprintf("http://127.0.0.1:9999/sql?query=%s",
url.QueryEscape("SELECT * FROM proxy ORDER BY RAND() limit 1")))
if err != nil {
return nil, err
}
defer httpResponse.Body.Close()
all, err := io.ReadAll(httpResponse.Body)
if err != nil {
return nil, err
}
var respStruct struct {
Error string `json:"error"`
Message []MyProxy `json:"message"`
}
err = json.Unmarshal(all, &respStruct)
if err != nil {
return nil, err
}
u := fmt.Sprintf("http://%s", respStruct.Message[0].Content)
return url.Parse(u)
}
transport := &http.Transport{Proxy: proxy}
client := &http.Client{Transport: transport}
httpResponse, err := client.Get(fmt.Sprintf("http://api.bilibili.com/x/space/acc/info?mid=%s", pUid))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "网络错误") return nil, errors.Wrap(err, "网络错误")
} }

@ -0,0 +1,45 @@
package platform_user
import (
"encoding/json"
"fmt"
"testing"
)
func TestRetrieveBilibili(t *testing.T) {
str := `{
"error": "",
"message": [
{
"id": 48,
"ip": "120.42.46.226",
"port": "6666",
"scheme_type": 0,
"content": "120.42.46.226:6666",
"assess_times": 16,
"success_times": 14,
"avg_response_time": 2.063625,
"continuous_failed_times": 0,
"score": 3.7924709776481986,
"insert_time": 1650852112,
"update_time": 1650853064
}
]
}`
var respStruct struct {
Error string `json:"error"`
Message []MyProxy `json:"message"`
}
err := json.Unmarshal([]byte(str), &respStruct)
if err != nil {
return
}
fmt.Printf("%+v\n", respStruct)
bilibili, err := RetrieveBilibili("2")
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", bilibili)
}

@ -6,8 +6,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"live-service/app/user_center/model" "live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/logic/platform_user" "live-service/app/user_center/rpc/internal/logic/platform_user"
"time"
"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"
@ -26,12 +24,12 @@ func NewRetrievePlatformUserLogic(ctx context.Context, svcCtx *svc.ServiceContex
return &RetrievePlatformUserLogic{ return &RetrievePlatformUserLogic{
ctx: ctx, ctx: ctx,
svcCtx: svcCtx, svcCtx: svcCtx,
platformUserRetriever: platform_user.NewUserRetriever(), platformUserRetriever: platform_user.NewUserRetriever(ctx, svcCtx),
Logger: logx.WithContext(ctx), Logger: logx.WithContext(ctx),
} }
} }
// RetrievePlatformUser 查询或创建用户 // RetrievePlatformUser 查询或创建用户(此时不查询平台用户信息)
func (l *RetrievePlatformUserLogic) RetrievePlatformUser(in *pb.PlatformUserReq) (*pb.PlatformUserResp, error) { func (l *RetrievePlatformUserLogic) RetrievePlatformUser(in *pb.PlatformUserReq) (*pb.PlatformUserResp, error) {
var err error var err error
dbPlatformUser, err := l.svcCtx.UserPlatformModel.FindOneByPlatformAndPUid(l.ctx, in.Platform, in.PUid) dbPlatformUser, err := l.svcCtx.UserPlatformModel.FindOneByPlatformAndPUid(l.ctx, in.Platform, in.PUid)
@ -40,73 +38,47 @@ func (l *RetrievePlatformUserLogic) RetrievePlatformUser(in *pb.PlatformUserReq)
return nil, err // sql错误 return nil, err // sql错误
} }
} }
// 根据 updateTime 判断是否需要更新 if dbPlatformUser != nil {
if dbPlatformUser != nil && time.Now().Add(time.Duration(l.svcCtx.Config.User.UpdateDuration)*time.Hour).After(dbPlatformUser.UpdateTime) { var username string
var username *string
if one, err := l.svcCtx.UserModel.FindOne(l.ctx, dbPlatformUser.UserId); err != nil { if one, err := l.svcCtx.UserModel.FindOne(l.ctx, dbPlatformUser.UserId); err != nil {
username = &one.Username username = one.Username
} }
return &pb.PlatformUserResp{ return &pb.PlatformUserResp{
User: l.buildPBUser(username, dbPlatformUser), User: l.buildPBUser(username, dbPlatformUser),
}, nil }, nil
} }
var platformUser *platform_user.PlatformUser
platformUser, err = l.platformUserRetriever.RetrieveUser(in.Platform, in.PUid)
if err != nil {
// 获取平台信息失败
return nil, errors.Wrap(err, "获取平台信息失败")
}
var dbUser model.User
if dbPlatformUser == nil {
// create // create
dbUser = model.User{ dbUser := &model.User{
Id: uuid.NextId(), Id: uuid.NextId(),
Username: "", Username: "",
} }
if _, err = l.svcCtx.UserModel.Insert(l.ctx, &dbUser); err != nil { if err = l.svcCtx.UserModel.Insert(l.ctx, dbUser); err != nil {
return nil, errors.Wrap(err, "插入用户数据失败") return nil, errors.Wrap(err, "插入用户数据失败")
} }
dbPlatformUser = &model.UserPlatform{ dbPlatformUser = &model.UserPlatform{
Id: uuid.NextId(), Id: uuid.NextId(),
UserId: dbUser.Id, UserId: dbUser.Id,
Platform: in.Platform, Platform: in.Platform,
POpenid: "", PInfo: "{}",
PUid: platformUser.PUid,
PUname: platformUser.PName,
PInfo: platformUser.PInfo,
PAvatar: platformUser.PAvatar,
} }
if _, err = l.svcCtx.UserPlatformModel.Insert(l.ctx, dbPlatformUser); err != nil { if err = l.svcCtx.UserPlatformModel.Insert(l.ctx, dbPlatformUser); err != nil {
return nil, errors.Wrap(err, "插入平台用户数据失败") return nil, errors.Wrap(err, "插入平台用户数据失败")
} }
} else {
// update
dbPlatformUser.PUid = platformUser.PUid
dbPlatformUser.PUname = platformUser.PName
dbPlatformUser.PAvatar = platformUser.PAvatar
dbPlatformUser.PInfo = platformUser.PInfo
if err = l.svcCtx.UserPlatformModel.Update(l.ctx, dbPlatformUser); err != nil {
return nil, errors.Wrap(err, "更新平台用户数据失败")
}
}
return &pb.PlatformUserResp{ return &pb.PlatformUserResp{
User: l.buildPBUser(&dbUser.Username, dbPlatformUser), User: l.buildPBUser(dbUser.Username, dbPlatformUser),
}, nil }, nil
} }
func (l *RetrievePlatformUserLogic) buildPBUser(username *string, dbPlatformUser *model.UserPlatform) *pb.User { func (l *RetrievePlatformUserLogic) buildPBUser(username string, dbPlatformUser *model.UserPlatform) *pb.User {
result := &pb.User{ return &pb.User{
Id: dbPlatformUser.UserId, Id: dbPlatformUser.UserId,
Username: username,
Platform: dbPlatformUser.Platform, Platform: dbPlatformUser.Platform,
PUid: dbPlatformUser.PUid, PUid: dbPlatformUser.PUid,
PUname: dbPlatformUser.PUname, PUname: dbPlatformUser.PUname,
PAvatar: dbPlatformUser.PAvatar, PAvatar: dbPlatformUser.PAvatar,
PInfo: dbPlatformUser.PInfo, PInfo: dbPlatformUser.PInfo,
} }
if username != nil {
result.Username = *username
}
return result
} }

@ -1,9 +1,11 @@
package svc package svc
import ( import (
"github.com/zeromicro/go-zero/core/stores/sqlx" "gorm.io/driver/mysql"
"gorm.io/gorm"
"live-service/app/user_center/model" "live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/config" "live-service/app/user_center/rpc/internal/config"
"log"
) )
type ServiceContext struct { type ServiceContext struct {
@ -14,9 +16,13 @@ type ServiceContext struct {
} }
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
gormDb, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{})
if err != nil {
log.Fatal(err)
}
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,
UserModel: model.NewUserModel(sqlx.NewMysql(c.DB.DataSource)), UserModel: model.NewUserModel(gormDb),
UserPlatformModel: model.NewUserPlatformModel(sqlx.NewMysql(c.DB.DataSource)), UserPlatformModel: model.NewUserPlatformModel(gormDb),
} }
} }

@ -1,35 +0,0 @@
package danmaku
import pbMq "live-service/app/pb/mq"
type HandlerFunc func(roomId int64, cmd string, dm *pbMq.MqDanmaku)
type Manager struct {
handlers map[string]HandlerFunc
}
func NewManager() *Manager {
return &Manager{
handlers: make(map[string]HandlerFunc),
}
}
func (m *Manager) Register(h HandlerFunc, cmd string, alias ...string) {
if _, ok := m.handlers[cmd]; ok {
return
}
m.handlers[cmd] = h
// alias
for _, s := range alias {
if _, ok := m.handlers[cmd]; ok {
continue
}
m.handlers[s] = h
}
}
func (m *Manager) Handle(roomId int64, cmd string, user *pbMq.MqDanmaku) {
if h, ok := m.handlers[cmd]; ok {
h(roomId, cmd, user)
}
}

@ -1,70 +0,0 @@
package danmaku
import (
"git.noahlan.cn/northlan/ntools-go/stringn/ac"
"strings"
)
type (
CMD struct {
IsCMD bool // 是否CMD
Arr []string // 具体CMD []string
}
Parser struct {
trie *ac.Trie
allKeyArr []string
keywordMap map[string]struct{}
}
ParserBuilder struct {
}
)
func NewCMDParser(keys []string) *Parser {
p := &Parser{
keywordMap: make(map[string]struct{}),
allKeyArr: make([]string, len(keys)),
}
for _, keyword := range keys {
p.keywordMap[keyword] = struct{}{}
p.allKeyArr = append(p.allKeyArr, keyword)
}
p.trie = ac.NewTrieBuilder().AddStrings(p.allKeyArr).Build()
return p
}
func (p *Parser) ParseTest(content string) {
p.trie.MatchString(content)
}
func (p *Parser) Parse(content string) *CMD {
// 移除多余空格,小写
tmpContent := strings.ToLower(strings.TrimSpace(content))
matches := p.trie.MatchString(tmpContent)
allKeyLen := 0
matchedKeyMap := make(map[string]struct{})
for _, match := range matches {
tmp := p.allKeyArr[match.Pattern()]
matchedKeyMap[tmp] = struct{}{}
allKeyLen += len(tmp)
}
isCMD := len(tmpContent) <= allKeyLen
// 避免同类型指令重复
arrMap := make(map[rune]struct{})
var matchedCmdArr []string
if isCMD {
matchedCmdArr = make([]string, 0, len(matchedKeyMap))
for s := range matchedKeyMap {
sRune := []rune(s)
if _, ok := arrMap[sRune[0]]; !ok {
arrMap[sRune[0]] = struct{}{}
matchedCmdArr = append(matchedCmdArr, s)
}
}
}
return &CMD{
IsCMD: len(tmpContent) <= allKeyLen,
Arr: matchedCmdArr,
}
}

@ -1,103 +0,0 @@
package danmaku
import (
"context"
"git.noahlan.cn/northlan/ntools-go/kafka"
"github.com/Shopify/sarama"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/protobuf/proto"
pbMq "live-service/app/pb/mq"
"live-service/app/user_center/rpc/internal/server"
"live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb"
kfk "live-service/common/kafka"
"strconv"
"sync"
)
type msgHandlerFunc func(data []byte, msgKey string)
type MsgToDBHandler struct {
context context.Context
ctx *svc.ServiceContext
svr *server.UserCenterServer
msgHandle map[string]msgHandlerFunc
cmdParser *Parser
commandManager *Manager
ConsumerGroup *kafka.ConsumerGroup
mutex sync.Mutex
logx.Logger
}
func (h *MsgToDBHandler) Init(context context.Context, ctx *svc.ServiceContext, svr *server.UserCenterServer) {
h.context = context
h.ctx = ctx
h.svr = svr
h.Logger = logx.WithContext(h.context)
cfg := ctx.Config.Danmaku.Kafka
h.msgHandle = make(map[string]msgHandlerFunc)
h.msgHandle["danmaku"] = h.handleDanmaku
h.cmdParser = NewCMDParser(ctx.Config.Danmaku.Command.Keys)
//
h.commandManager = NewManager()
h.commandManager.Register(h.handleJoinGame, "j", "J", "加入", "加入游戏")
var err error
h.ConsumerGroup, err = kafka.NewConsumerGroup(&kafka.ConsumerGroupConfig{
KafkaVersion: sarama.V3_1_0_0,
OffsetsInitial: sarama.OffsetNewest,
IsReturnErr: false,
UnMarshaler: kfk.ProtobufMarshaler,
}, cfg.Addr, []string{cfg.Topic}, cfg.ConsumerGroupId)
if err != nil {
h.Logger.Error(err)
}
}
func (h *MsgToDBHandler) handleJoinGame(_ int64, _ string, danmaku *pbMq.MqDanmaku) {
h.mutex.Lock()
defer h.mutex.Unlock()
_, err := h.svr.RetrievePlatformUser(h.context, &pb.PlatformUserReq{
Platform: danmaku.Platform,
PUid: strconv.FormatInt(danmaku.Uid, 10),
})
if err != nil {
return
}
}
func (h *MsgToDBHandler) handleDanmaku(data []byte, msgKey string) {
// msg proto
var msgFromMq pbMq.MqDanmaku
if err := proto.Unmarshal(data, &msgFromMq); err != nil {
h.Logger.Error("unmarshal msg err", err)
return
}
cmdStruct := h.cmdParser.Parse(msgFromMq.Content)
// 只处理命令
if cmdStruct.IsCMD {
for _, cmd := range cmdStruct.Arr {
h.commandManager.Handle(msgFromMq.LiveRoomId, cmd, &msgFromMq)
}
}
}
func (*MsgToDBHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }
func (*MsgToDBHandler) Cleanup(_ sarama.ConsumerGroupSession) error { return nil }
func (h *MsgToDBHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
for msg := range claim.Messages() {
if hFunc, ok := h.msgHandle[msg.Topic]; ok {
hFunc(msg.Value, string(msg.Key))
}
sess.MarkMessage(msg, "")
}
return nil
}

@ -1,20 +0,0 @@
package msg_transfer
import (
"context"
"live-service/app/user_center/rpc/internal/server"
"live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/msg_transfer/danmaku"
)
var (
danmakuMsgToDb danmaku.MsgToDBHandler
)
func Init(context context.Context, ctx *svc.ServiceContext, svr *server.UserCenterServer) {
danmakuMsgToDb.Init(context, ctx, svr)
}
func Run() {
go danmakuMsgToDb.ConsumerGroup.RegisterHandlerAndConsumer(&danmakuMsgToDb)
}

@ -25,10 +25,6 @@ func main() {
ctx := svc.NewServiceContext(c) ctx := svc.NewServiceContext(c)
svr := server.NewUserCenterServer(ctx) svr := server.NewUserCenterServer(ctx)
// msg_transfer
//msg_transfer.Init(context.Background(), ctx, svr)
//msg_transfer.Run()
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
pb.RegisterUserCenterServer(grpcServer, svr) pb.RegisterUserCenterServer(grpcServer, svr)

@ -6,10 +6,9 @@ func (m *default{{.upperStartCamelObject}}Model) Delete(ctx context.Context, {{.
} }
{{end}} {{.keys}} {{end}} {{.keys}}
_, err {{if .containsIndexCache}}={{else}}:={{end}} m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { err {{if .containsIndexCache}}={{else}}:={{end}} m.ExecCtx(ctx, func(conn *gorm.DB) *gorm.DB {
query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table) return conn.Delete(&{{.upperStartCamelObject}}{}, {{.lowerStartCamelPrimaryKey}})
return conn.ExecCtx(ctx, query, {{.lowerStartCamelPrimaryKey}}) }, {{.keyValues}}){{else}} err:= m.conn.WithContext(ctx).Delete(&{{.upperStartCamelObject}}{}, {{.lowerStartCamelPrimaryKey}}).Error
}, {{.keyValues}}){{else}}query := fmt.Sprintf("delete from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table) {{end}}
_,err:=m.conn.ExecCtx(ctx, query, {{.lowerStartCamelPrimaryKey}}){{end}}
return err return err
} }

@ -1,5 +1,5 @@
package {{.pkg}} package {{.pkg}}
import "github.com/zeromicro/go-zero/core/stores/sqlx" import "gorm.io/gorm"
var ErrNotFound = sqlx.ErrNotFound var ErrNotFound = gorm.ErrRecordNotFound

@ -3,7 +3,6 @@ func (m *default{{.upperStartCamelObject}}Model) formatPrimary(primary interface
return fmt.Sprintf("%s%v", {{.primaryKeyLeft}}, primary) return fmt.Sprintf("%s%v", {{.primaryKeyLeft}}, primary)
} }
func (m *default{{.upperStartCamelObject}}Model) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error { func (m *default{{.upperStartCamelObject}}Model) queryPrimary(conn *gorm.DB, v, primary interface{}) error {
query := fmt.Sprintf("select %s from %s where {{.originalPrimaryField}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table ) return conn.Model(&{{.upperStartCamelObject}}{}).Where("{{.originalPrimaryField}} = ?", primary).Take(v).Error
return conn.QueryRowCtx(ctx, v, query, primary)
} }

@ -2,9 +2,8 @@
func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) { func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) {
{{if .withCache}}{{.cacheKey}} {{if .withCache}}{{.cacheKey}}
var resp {{.upperStartCamelObject}} var resp {{.upperStartCamelObject}}
err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) { err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(conn *gorm.DB, v interface{}) (interface{}, error) {
query := fmt.Sprintf("select %s from %s where {{.originalField}} limit 1", {{.lowerStartCamelObject}}Rows, m.table) if err := conn.Model(&{{.upperStartCamelObject}}{}).Where("{{.originalField}}", {{.lowerStartCamelField}}).Take(&resp).Error; err != nil {
if err := conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelField}}); err != nil {
return nil, err return nil, err
} }
return resp.{{.upperStartCamelPrimaryKey}}, nil return resp.{{.upperStartCamelPrimaryKey}}, nil
@ -12,18 +11,17 @@ func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx co
switch err { switch err {
case nil: case nil:
return &resp, nil return &resp, nil
case sqlc.ErrNotFound: case gormc.ErrNotFound:
return nil, ErrNotFound return nil, ErrNotFound
default: default:
return nil, err return nil, err
} }
}{{else}}var resp {{.upperStartCamelObject}} }{{else}}var resp {{.upperStartCamelObject}}
query := fmt.Sprintf("select %s from %s where {{.originalField}} limit 1", {{.lowerStartCamelObject}}Rows, m.table ) err := m.conn.WithContext(ctx).Model(&{{.upperStartCamelObject}}{}).Where("{{.originalField}}", {{.lowerStartCamelField}}).Take(&resp).Error
err := m.conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelField}})
switch err { switch err {
case nil: case nil:
return &resp, nil return &resp, nil
case sqlc.ErrNotFound: case gormc.ErrNotFound:
return nil, ErrNotFound return nil, ErrNotFound
default: default:
return nil, err return nil, err

@ -2,24 +2,22 @@
func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) { func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) {
{{if .withCache}}{{.cacheKey}} {{if .withCache}}{{.cacheKey}}
var resp {{.upperStartCamelObject}} var resp {{.upperStartCamelObject}}
err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(conn *gorm.DB) *gorm.DB {
query := fmt.Sprintf("select %s from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table) return conn.Where("id = ?", {{.lowerStartCamelPrimaryKey}})
return conn.QueryRowCtx(ctx, v, query, {{.lowerStartCamelPrimaryKey}})
}) })
switch err { switch err {
case nil: case nil:
return &resp, nil return &resp, nil
case sqlc.ErrNotFound: case gormc.ErrNotFound:
return nil, ErrNotFound return nil, ErrNotFound
default: default:
return nil, err return nil, err
}{{else}}query := fmt.Sprintf("select %s from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table) }{{else}}var resp {{.upperStartCamelObject}}
var resp {{.upperStartCamelObject}} err := m.conn.WithContext(ctx).Model(&{{.upperStartCamelObject}}{}).Where("{{.originalPrimaryKey}} = ?", {{.lowerStartCamelPrimaryKey}}).Take(&resp).Error
err := m.conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelPrimaryKey}})
switch err { switch err {
case nil: case nil:
return &resp, nil return &resp, nil
case sqlc.ErrNotFound: case gormc.ErrNotFound:
return nil, ErrNotFound return nil, ErrNotFound
default: default:
return nil, err return nil, err

@ -1,12 +1,10 @@
import ( import (
"context" "context"
"database/sql" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"fmt"
"strings" "strings"
{{if .time}}"time"{{end}} {{if .time}}"time"{{end}}
"github.com/zeromicro/go-zero/core/stores/builder" "github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx" "github.com/zeromicro/go-zero/core/stringx"
"gorm.io/gorm"
) )

@ -1,13 +1,12 @@
import ( import (
"context" "context"
"database/sql"
"fmt" "fmt"
"strings" "strings"
{{if .time}}"time"{{end}} {{if .time}}"time"{{end}}
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"github.com/zeromicro/go-zero/core/stores/builder" "github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache" "github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx" "github.com/zeromicro/go-zero/core/stringx"
"gorm.io/gorm"
) )

@ -1,10 +1,8 @@
func (m *default{{.upperStartCamelObject}}Model) Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error) { func (m *default{{.upperStartCamelObject}}Model) Insert(ctx context.Context, data *{{.upperStartCamelObject}}) error {
{{if .withCache}}{{.keys}} {{if .withCache}}{{.keys}}
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { err := m.ExecCtx(ctx, func(conn *gorm.DB) *gorm.DB {
query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet) return conn.Save(&data)
return conn.ExecCtx(ctx, query, {{.expressionValues}}) }, {{.keyValues}}){{else}}err:=m.conn.WithContext(ctx).Save(&data).Error{{end}}
}, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet) return err
ret,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}}
return ret,err
} }

@ -1 +1 @@
Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error) Insert(ctx context.Context, data *{{.upperStartCamelObject}}) error

@ -1,7 +1,7 @@
func new{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf{{end}}) *default{{.upperStartCamelObject}}Model { func new{{.upperStartCamelObject}}Model(conn *gorm.DB{{if .withCache}}, c cache.CacheConf{{end}}) *default{{.upperStartCamelObject}}Model {
return &default{{.upperStartCamelObject}}Model{ return &default{{.upperStartCamelObject}}Model{
{{if .withCache}}CachedConn: sqlc.NewConn(conn, c){{else}}conn:conn{{end}}, {{if .withCache}}CachedConn: gormc.NewConn(conn, c){{else}}conn:conn{{end}},
table: {{.table}}, table: {{.table}},
} }
} }

@ -3,9 +3,12 @@ package {{.pkg}}
import ( import (
"github.com/zeromicro/go-zero/core/stores/cache" "github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx" "github.com/zeromicro/go-zero/core/stores/sqlx"
"gorm.io/gorm"
) )
{{else}} {{else}}
import "github.com/zeromicro/go-zero/core/stores/sqlx" import (
"gorm.io/gorm"
)
{{end}} {{end}}
var _ {{.upperStartCamelObject}}Model = (*custom{{.upperStartCamelObject}}Model)(nil) var _ {{.upperStartCamelObject}}Model = (*custom{{.upperStartCamelObject}}Model)(nil)
@ -22,7 +25,7 @@ type (
) )
// New{{.upperStartCamelObject}}Model returns a model for the database table. // New{{.upperStartCamelObject}}Model returns a model for the database table.
func New{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf{{end}}) {{.upperStartCamelObject}}Model { func New{{.upperStartCamelObject}}Model(conn *gorm.DB{{if .withCache}}, c cache.CacheConf{{end}}) {{.upperStartCamelObject}}Model {
return &custom{{.upperStartCamelObject}}Model{ return &custom{{.upperStartCamelObject}}Model{
default{{.upperStartCamelObject}}Model: new{{.upperStartCamelObject}}Model(conn{{if .withCache}}, c{{end}}), default{{.upperStartCamelObject}}Model: new{{.upperStartCamelObject}}Model(conn{{if .withCache}}, c{{end}}),
} }

@ -2,3 +2,8 @@
func (m *default{{.upperStartCamelObject}}Model) tableName() string { func (m *default{{.upperStartCamelObject}}Model) tableName() string {
return m.table return m.table
} }
func ({{.upperStartCamelObject}}) TableName() string {
model := default{{.upperStartCamelObject}}Model{}
return model.tableName()
}

@ -1 +1 @@
`db:"{{.field}}"` `gorm:"column:{{.field}}"`

@ -5,7 +5,7 @@ type (
} }
default{{.upperStartCamelObject}}Model struct { default{{.upperStartCamelObject}}Model struct {
{{if .withCache}}sqlc.CachedConn{{else}}conn sqlx.SqlConn{{end}} {{if .withCache}}gormc.CachedConn{{else}}conn *gorm.DB{{end}}
table string table string
} }

@ -1,10 +1,8 @@
func (m *default{{.upperStartCamelObject}}Model) Update(ctx context.Context, data *{{.upperStartCamelObject}}) error { func (m *default{{.upperStartCamelObject}}Model) Update(ctx context.Context, data *{{.upperStartCamelObject}}) error {
{{if .withCache}}{{.keys}} {{if .withCache}}{{.keys}}
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) { err := m.ExecCtx(ctx, func(conn *gorm.DB) *gorm.DB {
query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder) return conn.Save(data)
return conn.ExecCtx(ctx, query, {{.expressionValues}}) }, {{.keyValues}}){{else}}err:=m.conn.WithContext(ctx).Save(data).Error{{end}}
}, {{.keyValues}}){{else}}query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}}", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder)
_,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}}
return err return err
} }

@ -14,6 +14,7 @@ require (
) )
require ( require (
git.noahlan.cn/northlan/ntools-go/gorm-zero v1.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-semver v0.3.0 // indirect
@ -23,9 +24,9 @@ require (
github.com/eapache/go-resiliency v1.2.0 // indirect github.com/eapache/go-resiliency v1.2.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect github.com/eapache/queue v1.1.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-redis/redis/v8 v8.11.4 // indirect github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect github.com/golang/mock v1.6.0 // indirect
@ -41,6 +42,8 @@ require (
github.com/jcmturner/gofork v1.0.0 // indirect github.com/jcmturner/gofork v1.0.0 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.1 // indirect github.com/klauspost/compress v1.15.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
@ -53,23 +56,24 @@ require (
github.com/prometheus/common v0.30.0 // indirect github.com/prometheus/common v0.30.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect github.com/prometheus/procfs v0.7.3 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/robfig/cron/v3 v3.0.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.2 // indirect go.etcd.io/etcd/api/v3 v3.5.2 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect
go.etcd.io/etcd/client/v3 v3.5.2 // indirect go.etcd.io/etcd/client/v3 v3.5.2 // indirect
go.opentelemetry.io/otel v1.3.0 // indirect go.opentelemetry.io/otel v1.6.3 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.3.0 // indirect go.opentelemetry.io/otel/exporters/jaeger v1.3.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.3.0 // indirect go.opentelemetry.io/otel/exporters/zipkin v1.3.0 // indirect
go.opentelemetry.io/otel/sdk v1.3.0 // indirect go.opentelemetry.io/otel/sdk v1.3.0 // indirect
go.opentelemetry.io/otel/trace v1.3.0 // indirect go.opentelemetry.io/otel/trace v1.6.3 // indirect
go.uber.org/atomic v1.9.0 // indirect go.uber.org/atomic v1.9.0 // indirect
go.uber.org/automaxprocs v1.4.0 // indirect go.uber.org/automaxprocs v1.5.1 // indirect
go.uber.org/multierr v1.8.0 // indirect go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 // indirect golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
@ -77,6 +81,8 @@ require (
google.golang.org/genproto v0.0.0-20220228195345-15d65a4533f7 // indirect google.golang.org/genproto v0.0.0-20220228195345-15d65a4533f7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gorm.io/driver/mysql v1.3.3 // indirect
gorm.io/gorm v1.23.4 // indirect
k8s.io/api v0.20.12 // indirect k8s.io/api v0.20.12 // indirect
k8s.io/apimachinery v0.20.12 // indirect k8s.io/apimachinery v0.20.12 // indirect
k8s.io/client-go v0.20.12 // indirect k8s.io/client-go v0.20.12 // indirect

@ -31,6 +31,10 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.noahlan.cn/northlan/ntools-go/gorm-zero v1.0.0 h1:Em5V7PQoO3Okf5lugGHsdGzVTnInIFdPj4D8ykfpYYo=
git.noahlan.cn/northlan/ntools-go/gorm-zero v1.0.0/go.mod h1:fDeW2GCJEU5OEPMisWH9wyA/BiPZg6tK5FegDIaMURg=
git.noahlan.cn/northlan/ntools-go/gorm-zero v1.0.1 h1:c/vZx96FPV4xyZEsSvWAXzQH+S3QZ9ixMBv3faQzXSY=
git.noahlan.cn/northlan/ntools-go/gorm-zero v1.0.1/go.mod h1:fDeW2GCJEU5OEPMisWH9wyA/BiPZg6tK5FegDIaMURg=
git.noahlan.cn/northlan/ntools-go/kafka v1.0.1 h1:SDUwYRzksZ3Vcu7PTZxk+TEMF2f3gBiQEboKOhi1yfI= git.noahlan.cn/northlan/ntools-go/kafka v1.0.1 h1:SDUwYRzksZ3Vcu7PTZxk+TEMF2f3gBiQEboKOhi1yfI=
git.noahlan.cn/northlan/ntools-go/kafka v1.0.1/go.mod h1:RxX9JSUIr3Gbk+cvUwE5k+i08AgIK3TA9ayDJCMn2n8= git.noahlan.cn/northlan/ntools-go/kafka v1.0.1/go.mod h1:RxX9JSUIr3Gbk+cvUwE5k+i08AgIK3TA9ayDJCMn2n8=
git.noahlan.cn/northlan/ntools-go/stringn v1.0.0 h1:kQlk6JkJSX2JRsxtji6Ht1f3FfwdJiFEJ52k0ehjR8s= git.noahlan.cn/northlan/ntools-go/stringn v1.0.0 h1:kQlk6JkJSX2JRsxtji6Ht1f3FfwdJiFEJ52k0ehjR8s=
@ -152,6 +156,8 @@ github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI= github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
@ -164,6 +170,8 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg=
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w= github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
@ -273,6 +281,11 @@ github.com/jcmturner/gokrb5/v8 v8.4.2 h1:6ZIM6b/JJN0X8UM43ZOM6Z4SJzla+a/u7scXFJz
github.com/jcmturner/gokrb5/v8 v8.4.2/go.mod h1:sb+Xq/fTY5yktf/VxLsE3wlfPqQjp0aWNYyvBVK62bc= github.com/jcmturner/gokrb5/v8 v8.4.2/go.mod h1:sb+Xq/fTY5yktf/VxLsE3wlfPqQjp0aWNYyvBVK62bc=
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
@ -346,6 +359,7 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/openzipkin/zipkin-go v0.3.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0R4l6Zg0P1tTQ= github.com/openzipkin/zipkin-go v0.3.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0R4l6Zg0P1tTQ=
github.com/openzipkin/zipkin-go v0.4.0 h1:CtfRrOVZtbDj8rt1WXjklw0kqqJQwICrCKmlfUuBUUw= github.com/openzipkin/zipkin-go v0.4.0 h1:CtfRrOVZtbDj8rt1WXjklw0kqqJQwICrCKmlfUuBUUw=
github.com/openzipkin/zipkin-go v0.4.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0R4l6Zg0P1tTQ= github.com/openzipkin/zipkin-go v0.4.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0R4l6Zg0P1tTQ=
@ -384,6 +398,8 @@ github.com/rabbitmq/amqp091-go v1.1.0/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0V
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E=
github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
@ -411,6 +427,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
@ -438,6 +455,8 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y= go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y=
go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
go.opentelemetry.io/otel v1.6.3 h1:FLOfo8f9JzFVFVyU+MSRJc2HdEAXQgm7pIv2uFKRSZE=
go.opentelemetry.io/otel v1.6.3/go.mod h1:7BgNga5fNlF/iZjG06hM3yofffp0ofKCDwSXx1GC4dI=
go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0= go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0=
go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc= go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc=
go.opentelemetry.io/otel/exporters/zipkin v1.3.0 h1:uOD28dZ7yIKITTcUS6MeAGNHYy3uhP7DTkhcJM6onlQ= go.opentelemetry.io/otel/exporters/zipkin v1.3.0 h1:uOD28dZ7yIKITTcUS6MeAGNHYy3uhP7DTkhcJM6onlQ=
@ -446,12 +465,16 @@ go.opentelemetry.io/otel/sdk v1.3.0 h1:3278edCoH89MEJ0Ky8WQXVmDQv3FX4ZJ3Pp+9fJre
go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs= go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs=
go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY= go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY=
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk= go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
go.opentelemetry.io/otel/trace v1.6.3 h1:IqN4L+5b0mPNjdXIiZ90Ni4Bl5BRkDQywePLWemd9bc=
go.opentelemetry.io/otel/trace v1.6.3/go.mod h1:GNJQusJlUgZl9/TQBPKU/Y/ty+0iVB5fjhKeJGZPGFs=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/automaxprocs v1.4.0 h1:CpDZl6aOlLhReez+8S3eEotD7Jx0Os++lemPlMULQP0= go.uber.org/automaxprocs v1.4.0 h1:CpDZl6aOlLhReez+8S3eEotD7Jx0Os++lemPlMULQP0=
go.uber.org/automaxprocs v1.4.0/go.mod h1:/mTEdr7LvHhs0v7mjdxDreTz1OG5zdZGqgOnhWiR/+Q= go.uber.org/automaxprocs v1.4.0/go.mod h1:/mTEdr7LvHhs0v7mjdxDreTz1OG5zdZGqgOnhWiR/+Q=
go.uber.org/automaxprocs v1.5.1 h1:e1YG66Lrk73dn4qhg8WFSvhF0JuFQF0ERIp4rpuV8Qk=
go.uber.org/automaxprocs v1.5.1/go.mod h1:BF4eumQw0P9GtnuxxovUd06vwm1o18oMzFtK66vU6XU=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
@ -622,6 +645,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@ -809,6 +834,11 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.3.3 h1:jXG9ANrwBc4+bMvBcSl8zCfPBaVoPyBEBshA8dA93X8=
gorm.io/driver/mysql v1.3.3/go.mod h1:ChK6AHbHgDCFZyJp0F+BmVGb06PSIoh9uVYKAlRbb2U=
gorm.io/gorm v1.23.1/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.23.4 h1:1BKWM67O6CflSLcwGQR7ccfmC4ebOxQrTfOQGRE9wjg=
gorm.io/gorm v1.23.4/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

Loading…
Cancel
Save