diff --git a/app/auth_service/auth_service.go b/app/auth_service/auth_service.go index 0021b33..84a9dba 100644 --- a/app/auth_service/auth_service.go +++ b/app/auth_service/auth_service.go @@ -1,27 +1,27 @@ package main import ( - "flag" "fmt" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service" - "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/config" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/server" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/config" - "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/auth_service.yaml", "the config file") +const ServiceName = "auth_service" func main() { - flag.Parse() - var c config.Config - conf.MustLoad(*configFile, &c) + err := config.GetConfig(&c, ServiceName) + if err != nil { + panic(err) + } + ctx := svc.NewServiceContext(c) s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { @@ -33,6 +33,6 @@ func main() { }) defer s.Stop() - fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) + fmt.Printf("Starting rpc server at %s...\n", c.RpcServerConf.ListenOn) s.Start() } diff --git a/app/auth_service/auth_service.proto b/app/auth_service/auth_service.proto index 0328f93..5625d72 100644 --- a/app/auth_service/auth_service.proto +++ b/app/auth_service/auth_service.proto @@ -20,6 +20,7 @@ message Code2SessionRequest{ message Code2SessionResponse{ string OpenId = 1; string UnionId = 2; + uint64 UserId = 3; } message GetAccessTokenRequest{ diff --git a/app/auth_service/auth_service/auth_service.pb.go b/app/auth_service/auth_service/auth_service.pb.go index d31d671..0aed50a 100644 --- a/app/auth_service/auth_service/auth_service.pb.go +++ b/app/auth_service/auth_service/auth_service.pb.go @@ -173,6 +173,7 @@ type Code2SessionResponse struct { state protoimpl.MessageState `protogen:"open.v1"` OpenId string `protobuf:"bytes,1,opt,name=OpenId,proto3" json:"OpenId,omitempty"` UnionId string `protobuf:"bytes,2,opt,name=UnionId,proto3" json:"UnionId,omitempty"` + UserId uint64 `protobuf:"varint,3,opt,name=UserId,proto3" json:"UserId,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -221,6 +222,13 @@ func (x *Code2SessionResponse) GetUnionId() string { return "" } +func (x *Code2SessionResponse) GetUserId() uint64 { + if x != nil { + return x.UserId + } + return 0 +} + type GetAccessTokenRequest struct { state protoimpl.MessageState `protogen:"open.v1"` AppId string `protobuf:"bytes,1,opt,name=AppId,proto3" json:"AppId,omitempty"` @@ -324,36 +332,37 @@ var file_auth_service_proto_rawDesc = string([]byte{ 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x41, 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x41, 0x6e, 0x6f, 0x6e, 0x79, - 0x6d, 0x6f, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x48, 0x0a, 0x14, 0x43, 0x6f, 0x64, 0x65, + 0x6d, 0x6f, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x60, 0x0a, 0x14, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x55, 0x6e, 0x69, 0x6f, 0x6e, - 0x49, 0x64, 0x22, 0x2d, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, - 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x41, - 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x41, 0x70, 0x70, 0x49, - 0x64, 0x22, 0x3a, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, - 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x41, - 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0b, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0xf9, 0x01, - 0x0a, 0x0c, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x35, - 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x15, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, - 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x55, 0x0a, 0x0c, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65, - 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a, 0x0e, - 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x23, - 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, + 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x2d, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, - 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x61, - 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x41, 0x70, 0x70, 0x49, 0x64, 0x22, 0x3a, 0x0a, 0x16, 0x47, 0x65, 0x74, + 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, + 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, + 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0xf9, 0x01, 0x0a, 0x0c, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x35, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x15, + 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x55, 0x0a, + 0x0c, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, + 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x64, + 0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x22, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, + 0x43, 0x6f, 0x64, 0x65, 0x32, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, + 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x23, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, + 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x61, 0x75, + 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x42, 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, }) var ( diff --git a/app/auth_service/auth_service_client/auth_service.go b/app/auth_service/auth_service_client/auth_service.go index 378009a..42a96cb 100644 --- a/app/auth_service/auth_service_client/auth_service.go +++ b/app/auth_service/auth_service_client/auth_service.go @@ -6,19 +6,20 @@ package auth_service_client import ( "context" - auth_service2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service" + + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service" "github.com/zeromicro/go-zero/zrpc" "google.golang.org/grpc" ) type ( - Code2SessionRequest = auth_service2.Code2SessionRequest - Code2SessionResponse = auth_service2.Code2SessionResponse - GetAccessTokenRequest = auth_service2.GetAccessTokenRequest - GetAccessTokenResponse = auth_service2.GetAccessTokenResponse - Request = auth_service2.Request - Response = auth_service2.Response + Code2SessionRequest = auth_service.Code2SessionRequest + Code2SessionResponse = auth_service.Code2SessionResponse + GetAccessTokenRequest = auth_service.GetAccessTokenRequest + GetAccessTokenResponse = auth_service.GetAccessTokenResponse + Request = auth_service.Request + Response = auth_service.Response AuthService interface { Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) @@ -38,16 +39,16 @@ func NewAuthService(cli zrpc.Client) AuthService { } func (m *defaultAuthService) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) { - client := auth_service2.NewAuthServiceClient(m.cli.Conn()) + client := auth_service.NewAuthServiceClient(m.cli.Conn()) return client.Ping(ctx, in, opts...) } func (m *defaultAuthService) Code2Session(ctx context.Context, in *Code2SessionRequest, opts ...grpc.CallOption) (*Code2SessionResponse, error) { - client := auth_service2.NewAuthServiceClient(m.cli.Conn()) + client := auth_service.NewAuthServiceClient(m.cli.Conn()) return client.Code2Session(ctx, in, opts...) } func (m *defaultAuthService) GetAccessToken(ctx context.Context, in *GetAccessTokenRequest, opts ...grpc.CallOption) (*GetAccessTokenResponse, error) { - client := auth_service2.NewAuthServiceClient(m.cli.Conn()) + client := auth_service.NewAuthServiceClient(m.cli.Conn()) return client.GetAccessToken(ctx, in, opts...) } diff --git a/app/auth_service/internal/gen/dao/model/app_account.gen.go b/app/auth_service/internal/gen/dao/model/app_account.gen.go new file mode 100644 index 0000000..72e01ba --- /dev/null +++ b/app/auth_service/internal/gen/dao/model/app_account.gen.go @@ -0,0 +1,26 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package model + +import ( + "gorm.io/gorm" +) + +const TableNameAppAccount = "app_account" + +// AppAccount mapped from table +type AppAccount struct { + ID uint32 `gorm:"column:id;type:int unsigned;primaryKey;autoIncrement:true" json:"id"` + Type uint32 `gorm:"column:type;type:tinyint unsigned;not null;comment:类型(0:抖音,1:微信)" json:"type"` // 类型(0:抖音,1:微信) + AppID string `gorm:"column:app_id;type:char(20);not null;uniqueIndex:app_id,priority:1" json:"app_id"` + Secret string `gorm:"column:secret;type:char(40);not null" json:"secret"` + Remark *string `gorm:"column:remark;type:varchar(255);comment:备注" json:"remark"` // 备注 + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:time" json:"deleted_at"` +} + +// TableName AppAccount's table name +func (*AppAccount) TableName() string { + return TableNameAppAccount +} diff --git a/app/auth_service/internal/gen/dao/model/app_user.gen.go b/app/auth_service/internal/gen/dao/model/app_user.gen.go new file mode 100644 index 0000000..27b89da --- /dev/null +++ b/app/auth_service/internal/gen/dao/model/app_user.gen.go @@ -0,0 +1,27 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package model + +import ( + "time" +) + +const TableNameAppUser = "app_user" + +// AppUser mapped from table +type AppUser struct { + ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true;index:idx_app_user_id,priority:1" json:"id"` + AppAccountID uint32 `gorm:"column:app_account_id;type:int unsigned;not null;uniqueIndex:app_account_id_open_id,priority:1;comment:app_account表外键" json:"app_account_id"` // app_account表外键 + UserID *uint64 `gorm:"column:user_id;type:bigint unsigned" json:"user_id"` + Openid string `gorm:"column:openid;type:varchar(255);not null;uniqueIndex:app_account_id_open_id,priority:2" json:"openid"` + Unionid string `gorm:"column:unionid;type:varchar(255);not null" json:"unionid"` + AnonymousOpenid string `gorm:"column:anonymous_openid;type:varchar(255);not null;comment:匿名openid" json:"anonymous_openid"` // 匿名openid + CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 +} + +// TableName AppUser's table name +func (*AppUser) TableName() string { + return TableNameAppUser +} diff --git a/app/auth_service/internal/gen/dao/query/app_account.gen.go b/app/auth_service/internal/gen/dao/query/app_account.gen.go new file mode 100644 index 0000000..19d6466 --- /dev/null +++ b/app/auth_service/internal/gen/dao/query/app_account.gen.go @@ -0,0 +1,349 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/gen/dao/model" +) + +func newAppAccount(db *gorm.DB, opts ...gen.DOOption) appAccount { + _appAccount := appAccount{} + + _appAccount.appAccountDo.UseDB(db, opts...) + _appAccount.appAccountDo.UseModel(&model.AppAccount{}) + + tableName := _appAccount.appAccountDo.TableName() + _appAccount.ALL = field.NewAsterisk(tableName) + _appAccount.ID = field.NewUint32(tableName, "id") + _appAccount.Type = field.NewUint32(tableName, "type") + _appAccount.AppID = field.NewString(tableName, "app_id") + _appAccount.Secret = field.NewString(tableName, "secret") + _appAccount.Remark = field.NewString(tableName, "remark") + _appAccount.DeletedAt = field.NewField(tableName, "deleted_at") + + _appAccount.fillFieldMap() + + return _appAccount +} + +type appAccount struct { + appAccountDo appAccountDo + + ALL field.Asterisk + ID field.Uint32 + Type field.Uint32 // 类型(0:抖音,1:微信) + AppID field.String + Secret field.String + Remark field.String // 备注 + DeletedAt field.Field + + fieldMap map[string]field.Expr +} + +func (a appAccount) Table(newTableName string) *appAccount { + a.appAccountDo.UseTable(newTableName) + return a.updateTableName(newTableName) +} + +func (a appAccount) As(alias string) *appAccount { + a.appAccountDo.DO = *(a.appAccountDo.As(alias).(*gen.DO)) + return a.updateTableName(alias) +} + +func (a *appAccount) updateTableName(table string) *appAccount { + a.ALL = field.NewAsterisk(table) + a.ID = field.NewUint32(table, "id") + a.Type = field.NewUint32(table, "type") + a.AppID = field.NewString(table, "app_id") + a.Secret = field.NewString(table, "secret") + a.Remark = field.NewString(table, "remark") + a.DeletedAt = field.NewField(table, "deleted_at") + + a.fillFieldMap() + + return a +} + +func (a *appAccount) WithContext(ctx context.Context) *appAccountDo { + return a.appAccountDo.WithContext(ctx) +} + +func (a appAccount) TableName() string { return a.appAccountDo.TableName() } + +func (a appAccount) Alias() string { return a.appAccountDo.Alias() } + +func (a appAccount) Columns(cols ...field.Expr) gen.Columns { return a.appAccountDo.Columns(cols...) } + +func (a *appAccount) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := a.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (a *appAccount) fillFieldMap() { + a.fieldMap = make(map[string]field.Expr, 6) + a.fieldMap["id"] = a.ID + a.fieldMap["type"] = a.Type + a.fieldMap["app_id"] = a.AppID + a.fieldMap["secret"] = a.Secret + a.fieldMap["remark"] = a.Remark + a.fieldMap["deleted_at"] = a.DeletedAt +} + +func (a appAccount) clone(db *gorm.DB) appAccount { + a.appAccountDo.ReplaceConnPool(db.Statement.ConnPool) + return a +} + +func (a appAccount) replaceDB(db *gorm.DB) appAccount { + a.appAccountDo.ReplaceDB(db) + return a +} + +type appAccountDo struct{ gen.DO } + +func (a appAccountDo) Debug() *appAccountDo { + return a.withDO(a.DO.Debug()) +} + +func (a appAccountDo) WithContext(ctx context.Context) *appAccountDo { + return a.withDO(a.DO.WithContext(ctx)) +} + +func (a appAccountDo) ReadDB() *appAccountDo { + return a.Clauses(dbresolver.Read) +} + +func (a appAccountDo) WriteDB() *appAccountDo { + return a.Clauses(dbresolver.Write) +} + +func (a appAccountDo) Session(config *gorm.Session) *appAccountDo { + return a.withDO(a.DO.Session(config)) +} + +func (a appAccountDo) Clauses(conds ...clause.Expression) *appAccountDo { + return a.withDO(a.DO.Clauses(conds...)) +} + +func (a appAccountDo) Returning(value interface{}, columns ...string) *appAccountDo { + return a.withDO(a.DO.Returning(value, columns...)) +} + +func (a appAccountDo) Not(conds ...gen.Condition) *appAccountDo { + return a.withDO(a.DO.Not(conds...)) +} + +func (a appAccountDo) Or(conds ...gen.Condition) *appAccountDo { + return a.withDO(a.DO.Or(conds...)) +} + +func (a appAccountDo) Select(conds ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Select(conds...)) +} + +func (a appAccountDo) Where(conds ...gen.Condition) *appAccountDo { + return a.withDO(a.DO.Where(conds...)) +} + +func (a appAccountDo) Order(conds ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Order(conds...)) +} + +func (a appAccountDo) Distinct(cols ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Distinct(cols...)) +} + +func (a appAccountDo) Omit(cols ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Omit(cols...)) +} + +func (a appAccountDo) Join(table schema.Tabler, on ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Join(table, on...)) +} + +func (a appAccountDo) LeftJoin(table schema.Tabler, on ...field.Expr) *appAccountDo { + return a.withDO(a.DO.LeftJoin(table, on...)) +} + +func (a appAccountDo) RightJoin(table schema.Tabler, on ...field.Expr) *appAccountDo { + return a.withDO(a.DO.RightJoin(table, on...)) +} + +func (a appAccountDo) Group(cols ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Group(cols...)) +} + +func (a appAccountDo) Having(conds ...gen.Condition) *appAccountDo { + return a.withDO(a.DO.Having(conds...)) +} + +func (a appAccountDo) Limit(limit int) *appAccountDo { + return a.withDO(a.DO.Limit(limit)) +} + +func (a appAccountDo) Offset(offset int) *appAccountDo { + return a.withDO(a.DO.Offset(offset)) +} + +func (a appAccountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appAccountDo { + return a.withDO(a.DO.Scopes(funcs...)) +} + +func (a appAccountDo) Unscoped() *appAccountDo { + return a.withDO(a.DO.Unscoped()) +} + +func (a appAccountDo) Create(values ...*model.AppAccount) error { + if len(values) == 0 { + return nil + } + return a.DO.Create(values) +} + +func (a appAccountDo) CreateInBatches(values []*model.AppAccount, batchSize int) error { + return a.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (a appAccountDo) Save(values ...*model.AppAccount) error { + if len(values) == 0 { + return nil + } + return a.DO.Save(values) +} + +func (a appAccountDo) First() (*model.AppAccount, error) { + if result, err := a.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) Take() (*model.AppAccount, error) { + if result, err := a.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) Last() (*model.AppAccount, error) { + if result, err := a.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) Find() ([]*model.AppAccount, error) { + result, err := a.DO.Find() + return result.([]*model.AppAccount), err +} + +func (a appAccountDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppAccount, err error) { + buf := make([]*model.AppAccount, 0, batchSize) + err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (a appAccountDo) FindInBatches(result *[]*model.AppAccount, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return a.DO.FindInBatches(result, batchSize, fc) +} + +func (a appAccountDo) Attrs(attrs ...field.AssignExpr) *appAccountDo { + return a.withDO(a.DO.Attrs(attrs...)) +} + +func (a appAccountDo) Assign(attrs ...field.AssignExpr) *appAccountDo { + return a.withDO(a.DO.Assign(attrs...)) +} + +func (a appAccountDo) Joins(fields ...field.RelationField) *appAccountDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Joins(_f)) + } + return &a +} + +func (a appAccountDo) Preload(fields ...field.RelationField) *appAccountDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Preload(_f)) + } + return &a +} + +func (a appAccountDo) FirstOrInit() (*model.AppAccount, error) { + if result, err := a.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) FirstOrCreate() (*model.AppAccount, error) { + if result, err := a.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) FindByPage(offset int, limit int) (result []*model.AppAccount, count int64, err error) { + result, err = a.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = a.Offset(-1).Limit(-1).Count() + return +} + +func (a appAccountDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = a.Count() + if err != nil { + return + } + + err = a.Offset(offset).Limit(limit).Scan(result) + return +} + +func (a appAccountDo) Scan(result interface{}) (err error) { + return a.DO.Scan(result) +} + +func (a appAccountDo) Delete(models ...*model.AppAccount) (result gen.ResultInfo, err error) { + return a.DO.Delete(models) +} + +func (a *appAccountDo) withDO(do gen.Dao) *appAccountDo { + a.DO = *do.(*gen.DO) + return a +} diff --git a/app/auth_service/internal/gen/dao/query/app_account.gen_test.go b/app/auth_service/internal/gen/dao/query/app_account.gen_test.go new file mode 100644 index 0000000..2468067 --- /dev/null +++ b/app/auth_service/internal/gen/dao/query/app_account.gen_test.go @@ -0,0 +1,145 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + "fmt" + "testing" + + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/gen/dao/model" + "gorm.io/gen" + "gorm.io/gen/field" + "gorm.io/gorm/clause" +) + +func init() { + InitializeDB() + err := _gen_test_db.AutoMigrate(&model.AppAccount{}) + if err != nil { + fmt.Printf("Error: AutoMigrate(&model.AppAccount{}) fail: %s", err) + } +} + +func Test_appAccountQuery(t *testing.T) { + appAccount := newAppAccount(_gen_test_db) + appAccount = *appAccount.As(appAccount.TableName()) + _do := appAccount.WithContext(context.Background()).Debug() + + primaryKey := field.NewString(appAccount.TableName(), clause.PrimaryKey) + _, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete() + if err != nil { + t.Error("clean table fail:", err) + return + } + + _, ok := appAccount.GetFieldByName("") + if ok { + t.Error("GetFieldByName(\"\") from appAccount success") + } + + err = _do.Create(&model.AppAccount{}) + if err != nil { + t.Error("create item in table fail:", err) + } + + err = _do.Save(&model.AppAccount{}) + if err != nil { + t.Error("create item in table fail:", err) + } + + err = _do.CreateInBatches([]*model.AppAccount{{}, {}}, 10) + if err != nil { + t.Error("create item in table fail:", err) + } + + _, err = _do.Select(appAccount.ALL).Take() + if err != nil { + t.Error("Take() on table fail:", err) + } + + _, err = _do.First() + if err != nil { + t.Error("First() on table fail:", err) + } + + _, err = _do.Last() + if err != nil { + t.Error("First() on table fail:", err) + } + + _, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil }) + if err != nil { + t.Error("FindInBatch() on table fail:", err) + } + + err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.AppAccount{}, 10, func(tx gen.Dao, batch int) error { return nil }) + if err != nil { + t.Error("FindInBatches() on table fail:", err) + } + + _, err = _do.Select(appAccount.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() + if err != nil { + t.Error("Find() on table fail:", err) + } + + _, err = _do.Distinct(primaryKey).Take() + if err != nil { + t.Error("select Distinct() on table fail:", err) + } + + _, err = _do.Select(appAccount.ALL).Omit(primaryKey).Take() + if err != nil { + t.Error("Omit() on table fail:", err) + } + + _, err = _do.Group(primaryKey).Find() + if err != nil { + t.Error("Group() on table fail:", err) + } + + _, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find() + if err != nil { + t.Error("Scopes() on table fail:", err) + } + + _, _, err = _do.FindByPage(0, 1) + if err != nil { + t.Error("FindByPage() on table fail:", err) + } + + _, err = _do.ScanByPage(&model.AppAccount{}, 0, 1) + if err != nil { + t.Error("ScanByPage() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() + if err != nil { + t.Error("FirstOrInit() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() + if err != nil { + t.Error("FirstOrCreate() on table fail:", err) + } + + var _a _another + var _aPK = field.NewString(_a.TableName(), "id") + + err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) + if err != nil { + t.Error("Join() on table fail:", err) + } + + err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) + if err != nil { + t.Error("LeftJoin() on table fail:", err) + } + + _, err = _do.Not().Or().Clauses().Take() + if err != nil { + t.Error("Not/Or/Clauses on table fail:", err) + } +} diff --git a/app/auth_service/internal/gen/dao/query/app_user.gen.go b/app/auth_service/internal/gen/dao/query/app_user.gen.go new file mode 100644 index 0000000..a668e82 --- /dev/null +++ b/app/auth_service/internal/gen/dao/query/app_user.gen.go @@ -0,0 +1,351 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/gen/dao/model" +) + +func newAppUser(db *gorm.DB, opts ...gen.DOOption) appUser { + _appUser := appUser{} + + _appUser.appUserDo.UseDB(db, opts...) + _appUser.appUserDo.UseModel(&model.AppUser{}) + + tableName := _appUser.appUserDo.TableName() + _appUser.ALL = field.NewAsterisk(tableName) + _appUser.ID = field.NewUint64(tableName, "id") + _appUser.AppAccountID = field.NewUint32(tableName, "app_account_id") + _appUser.UserID = field.NewUint64(tableName, "user_id") + _appUser.Openid = field.NewString(tableName, "openid") + _appUser.Unionid = field.NewString(tableName, "unionid") + _appUser.AnonymousOpenid = field.NewString(tableName, "anonymous_openid") + _appUser.CreatedAt = field.NewTime(tableName, "created_at") + + _appUser.fillFieldMap() + + return _appUser +} + +type appUser struct { + appUserDo appUserDo + + ALL field.Asterisk + ID field.Uint64 + AppAccountID field.Uint32 // app_account表外键 + UserID field.Uint64 + Openid field.String + Unionid field.String + AnonymousOpenid field.String // 匿名openid + CreatedAt field.Time // 创建时间 + + fieldMap map[string]field.Expr +} + +func (a appUser) Table(newTableName string) *appUser { + a.appUserDo.UseTable(newTableName) + return a.updateTableName(newTableName) +} + +func (a appUser) As(alias string) *appUser { + a.appUserDo.DO = *(a.appUserDo.As(alias).(*gen.DO)) + return a.updateTableName(alias) +} + +func (a *appUser) updateTableName(table string) *appUser { + a.ALL = field.NewAsterisk(table) + a.ID = field.NewUint64(table, "id") + a.AppAccountID = field.NewUint32(table, "app_account_id") + a.UserID = field.NewUint64(table, "user_id") + a.Openid = field.NewString(table, "openid") + a.Unionid = field.NewString(table, "unionid") + a.AnonymousOpenid = field.NewString(table, "anonymous_openid") + a.CreatedAt = field.NewTime(table, "created_at") + + a.fillFieldMap() + + return a +} + +func (a *appUser) WithContext(ctx context.Context) *appUserDo { return a.appUserDo.WithContext(ctx) } + +func (a appUser) TableName() string { return a.appUserDo.TableName() } + +func (a appUser) Alias() string { return a.appUserDo.Alias() } + +func (a appUser) Columns(cols ...field.Expr) gen.Columns { return a.appUserDo.Columns(cols...) } + +func (a *appUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := a.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (a *appUser) fillFieldMap() { + a.fieldMap = make(map[string]field.Expr, 7) + a.fieldMap["id"] = a.ID + a.fieldMap["app_account_id"] = a.AppAccountID + a.fieldMap["user_id"] = a.UserID + a.fieldMap["openid"] = a.Openid + a.fieldMap["unionid"] = a.Unionid + a.fieldMap["anonymous_openid"] = a.AnonymousOpenid + a.fieldMap["created_at"] = a.CreatedAt +} + +func (a appUser) clone(db *gorm.DB) appUser { + a.appUserDo.ReplaceConnPool(db.Statement.ConnPool) + return a +} + +func (a appUser) replaceDB(db *gorm.DB) appUser { + a.appUserDo.ReplaceDB(db) + return a +} + +type appUserDo struct{ gen.DO } + +func (a appUserDo) Debug() *appUserDo { + return a.withDO(a.DO.Debug()) +} + +func (a appUserDo) WithContext(ctx context.Context) *appUserDo { + return a.withDO(a.DO.WithContext(ctx)) +} + +func (a appUserDo) ReadDB() *appUserDo { + return a.Clauses(dbresolver.Read) +} + +func (a appUserDo) WriteDB() *appUserDo { + return a.Clauses(dbresolver.Write) +} + +func (a appUserDo) Session(config *gorm.Session) *appUserDo { + return a.withDO(a.DO.Session(config)) +} + +func (a appUserDo) Clauses(conds ...clause.Expression) *appUserDo { + return a.withDO(a.DO.Clauses(conds...)) +} + +func (a appUserDo) Returning(value interface{}, columns ...string) *appUserDo { + return a.withDO(a.DO.Returning(value, columns...)) +} + +func (a appUserDo) Not(conds ...gen.Condition) *appUserDo { + return a.withDO(a.DO.Not(conds...)) +} + +func (a appUserDo) Or(conds ...gen.Condition) *appUserDo { + return a.withDO(a.DO.Or(conds...)) +} + +func (a appUserDo) Select(conds ...field.Expr) *appUserDo { + return a.withDO(a.DO.Select(conds...)) +} + +func (a appUserDo) Where(conds ...gen.Condition) *appUserDo { + return a.withDO(a.DO.Where(conds...)) +} + +func (a appUserDo) Order(conds ...field.Expr) *appUserDo { + return a.withDO(a.DO.Order(conds...)) +} + +func (a appUserDo) Distinct(cols ...field.Expr) *appUserDo { + return a.withDO(a.DO.Distinct(cols...)) +} + +func (a appUserDo) Omit(cols ...field.Expr) *appUserDo { + return a.withDO(a.DO.Omit(cols...)) +} + +func (a appUserDo) Join(table schema.Tabler, on ...field.Expr) *appUserDo { + return a.withDO(a.DO.Join(table, on...)) +} + +func (a appUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) *appUserDo { + return a.withDO(a.DO.LeftJoin(table, on...)) +} + +func (a appUserDo) RightJoin(table schema.Tabler, on ...field.Expr) *appUserDo { + return a.withDO(a.DO.RightJoin(table, on...)) +} + +func (a appUserDo) Group(cols ...field.Expr) *appUserDo { + return a.withDO(a.DO.Group(cols...)) +} + +func (a appUserDo) Having(conds ...gen.Condition) *appUserDo { + return a.withDO(a.DO.Having(conds...)) +} + +func (a appUserDo) Limit(limit int) *appUserDo { + return a.withDO(a.DO.Limit(limit)) +} + +func (a appUserDo) Offset(offset int) *appUserDo { + return a.withDO(a.DO.Offset(offset)) +} + +func (a appUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appUserDo { + return a.withDO(a.DO.Scopes(funcs...)) +} + +func (a appUserDo) Unscoped() *appUserDo { + return a.withDO(a.DO.Unscoped()) +} + +func (a appUserDo) Create(values ...*model.AppUser) error { + if len(values) == 0 { + return nil + } + return a.DO.Create(values) +} + +func (a appUserDo) CreateInBatches(values []*model.AppUser, batchSize int) error { + return a.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (a appUserDo) Save(values ...*model.AppUser) error { + if len(values) == 0 { + return nil + } + return a.DO.Save(values) +} + +func (a appUserDo) First() (*model.AppUser, error) { + if result, err := a.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) Take() (*model.AppUser, error) { + if result, err := a.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) Last() (*model.AppUser, error) { + if result, err := a.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) Find() ([]*model.AppUser, error) { + result, err := a.DO.Find() + return result.([]*model.AppUser), err +} + +func (a appUserDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppUser, err error) { + buf := make([]*model.AppUser, 0, batchSize) + err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (a appUserDo) FindInBatches(result *[]*model.AppUser, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return a.DO.FindInBatches(result, batchSize, fc) +} + +func (a appUserDo) Attrs(attrs ...field.AssignExpr) *appUserDo { + return a.withDO(a.DO.Attrs(attrs...)) +} + +func (a appUserDo) Assign(attrs ...field.AssignExpr) *appUserDo { + return a.withDO(a.DO.Assign(attrs...)) +} + +func (a appUserDo) Joins(fields ...field.RelationField) *appUserDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Joins(_f)) + } + return &a +} + +func (a appUserDo) Preload(fields ...field.RelationField) *appUserDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Preload(_f)) + } + return &a +} + +func (a appUserDo) FirstOrInit() (*model.AppUser, error) { + if result, err := a.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) FirstOrCreate() (*model.AppUser, error) { + if result, err := a.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) FindByPage(offset int, limit int) (result []*model.AppUser, count int64, err error) { + result, err = a.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = a.Offset(-1).Limit(-1).Count() + return +} + +func (a appUserDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = a.Count() + if err != nil { + return + } + + err = a.Offset(offset).Limit(limit).Scan(result) + return +} + +func (a appUserDo) Scan(result interface{}) (err error) { + return a.DO.Scan(result) +} + +func (a appUserDo) Delete(models ...*model.AppUser) (result gen.ResultInfo, err error) { + return a.DO.Delete(models) +} + +func (a *appUserDo) withDO(do gen.Dao) *appUserDo { + a.DO = *do.(*gen.DO) + return a +} diff --git a/app/auth_service/internal/gen/dao/query/app_user.gen_test.go b/app/auth_service/internal/gen/dao/query/app_user.gen_test.go new file mode 100644 index 0000000..ab74225 --- /dev/null +++ b/app/auth_service/internal/gen/dao/query/app_user.gen_test.go @@ -0,0 +1,145 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + "fmt" + "testing" + + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/gen/dao/model" + "gorm.io/gen" + "gorm.io/gen/field" + "gorm.io/gorm/clause" +) + +func init() { + InitializeDB() + err := _gen_test_db.AutoMigrate(&model.AppUser{}) + if err != nil { + fmt.Printf("Error: AutoMigrate(&model.AppUser{}) fail: %s", err) + } +} + +func Test_appUserQuery(t *testing.T) { + appUser := newAppUser(_gen_test_db) + appUser = *appUser.As(appUser.TableName()) + _do := appUser.WithContext(context.Background()).Debug() + + primaryKey := field.NewString(appUser.TableName(), clause.PrimaryKey) + _, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete() + if err != nil { + t.Error("clean table fail:", err) + return + } + + _, ok := appUser.GetFieldByName("") + if ok { + t.Error("GetFieldByName(\"\") from appUser success") + } + + err = _do.Create(&model.AppUser{}) + if err != nil { + t.Error("create item in table fail:", err) + } + + err = _do.Save(&model.AppUser{}) + if err != nil { + t.Error("create item in table fail:", err) + } + + err = _do.CreateInBatches([]*model.AppUser{{}, {}}, 10) + if err != nil { + t.Error("create item in table fail:", err) + } + + _, err = _do.Select(appUser.ALL).Take() + if err != nil { + t.Error("Take() on table fail:", err) + } + + _, err = _do.First() + if err != nil { + t.Error("First() on table fail:", err) + } + + _, err = _do.Last() + if err != nil { + t.Error("First() on table fail:", err) + } + + _, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil }) + if err != nil { + t.Error("FindInBatch() on table fail:", err) + } + + err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.AppUser{}, 10, func(tx gen.Dao, batch int) error { return nil }) + if err != nil { + t.Error("FindInBatches() on table fail:", err) + } + + _, err = _do.Select(appUser.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() + if err != nil { + t.Error("Find() on table fail:", err) + } + + _, err = _do.Distinct(primaryKey).Take() + if err != nil { + t.Error("select Distinct() on table fail:", err) + } + + _, err = _do.Select(appUser.ALL).Omit(primaryKey).Take() + if err != nil { + t.Error("Omit() on table fail:", err) + } + + _, err = _do.Group(primaryKey).Find() + if err != nil { + t.Error("Group() on table fail:", err) + } + + _, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find() + if err != nil { + t.Error("Scopes() on table fail:", err) + } + + _, _, err = _do.FindByPage(0, 1) + if err != nil { + t.Error("FindByPage() on table fail:", err) + } + + _, err = _do.ScanByPage(&model.AppUser{}, 0, 1) + if err != nil { + t.Error("ScanByPage() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() + if err != nil { + t.Error("FirstOrInit() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() + if err != nil { + t.Error("FirstOrCreate() on table fail:", err) + } + + var _a _another + var _aPK = field.NewString(_a.TableName(), "id") + + err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) + if err != nil { + t.Error("Join() on table fail:", err) + } + + err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) + if err != nil { + t.Error("LeftJoin() on table fail:", err) + } + + _, err = _do.Not().Or().Clauses().Take() + if err != nil { + t.Error("Not/Or/Clauses on table fail:", err) + } +} diff --git a/app/auth_service/internal/gen/dao/query/gen.go b/app/auth_service/internal/gen/dao/query/gen.go new file mode 100644 index 0000000..72d2034 --- /dev/null +++ b/app/auth_service/internal/gen/dao/query/gen.go @@ -0,0 +1,99 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + "database/sql" + + "gorm.io/gorm" + + "gorm.io/gen" + + "gorm.io/plugin/dbresolver" +) + +func Use(db *gorm.DB, opts ...gen.DOOption) *Query { + return &Query{ + db: db, + AppAccount: newAppAccount(db, opts...), + AppUser: newAppUser(db, opts...), + } +} + +type Query struct { + db *gorm.DB + + AppAccount appAccount + AppUser appUser +} + +func (q *Query) Available() bool { return q.db != nil } + +func (q *Query) clone(db *gorm.DB) *Query { + return &Query{ + db: db, + AppAccount: q.AppAccount.clone(db), + AppUser: q.AppUser.clone(db), + } +} + +func (q *Query) ReadDB() *Query { + return q.ReplaceDB(q.db.Clauses(dbresolver.Read)) +} + +func (q *Query) WriteDB() *Query { + return q.ReplaceDB(q.db.Clauses(dbresolver.Write)) +} + +func (q *Query) ReplaceDB(db *gorm.DB) *Query { + return &Query{ + db: db, + AppAccount: q.AppAccount.replaceDB(db), + AppUser: q.AppUser.replaceDB(db), + } +} + +type queryCtx struct { + AppAccount *appAccountDo + AppUser *appUserDo +} + +func (q *Query) WithContext(ctx context.Context) *queryCtx { + return &queryCtx{ + AppAccount: q.AppAccount.WithContext(ctx), + AppUser: q.AppUser.WithContext(ctx), + } +} + +func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error { + return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...) +} + +func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx { + tx := q.db.Begin(opts...) + return &QueryTx{Query: q.clone(tx), Error: tx.Error} +} + +type QueryTx struct { + *Query + Error error +} + +func (q *QueryTx) Commit() error { + return q.db.Commit().Error +} + +func (q *QueryTx) Rollback() error { + return q.db.Rollback().Error +} + +func (q *QueryTx) SavePoint(name string) error { + return q.db.SavePoint(name).Error +} + +func (q *QueryTx) RollbackTo(name string) error { + return q.db.RollbackTo(name).Error +} diff --git a/app/auth_service/internal/gen/dao/query/gen_test.go b/app/auth_service/internal/gen/dao/query/gen_test.go new file mode 100644 index 0000000..f3eda61 --- /dev/null +++ b/app/auth_service/internal/gen/dao/query/gen_test.go @@ -0,0 +1,119 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + "fmt" + "reflect" + "sync" + "testing" + + "gorm.io/driver/sqlite" + "gorm.io/gorm" +) + +type Input struct { + Args []interface{} +} + +type Expectation struct { + Ret []interface{} +} + +type TestCase struct { + Input + Expectation +} + +const _gen_test_db_name = "gen_test.db" + +var _gen_test_db *gorm.DB +var _gen_test_once sync.Once + +func init() { + InitializeDB() + _gen_test_db.AutoMigrate(&_another{}) +} + +func InitializeDB() { + _gen_test_once.Do(func() { + var err error + _gen_test_db, err = gorm.Open(sqlite.Open(_gen_test_db_name), &gorm.Config{}) + if err != nil { + panic(fmt.Errorf("open sqlite %q fail: %w", _gen_test_db_name, err)) + } + }) +} + +func assert(t *testing.T, methodName string, res, exp interface{}) { + if !reflect.DeepEqual(res, exp) { + t.Errorf("%v() gotResult = %v, want %v", methodName, res, exp) + } +} + +type _another struct { + ID uint64 `gorm:"primaryKey"` +} + +func (*_another) TableName() string { return "another_for_unit_test" } + +func Test_Available(t *testing.T) { + if !Use(_gen_test_db).Available() { + t.Errorf("query.Available() == false") + } +} + +func Test_WithContext(t *testing.T) { + query := Use(_gen_test_db) + if !query.Available() { + t.Errorf("query Use(_gen_test_db) fail: query.Available() == false") + } + + type Content string + var key, value Content = "gen_tag", "unit_test" + qCtx := query.WithContext(context.WithValue(context.Background(), key, value)) + + for _, ctx := range []context.Context{ + qCtx.AppAccount.UnderlyingDB().Statement.Context, + qCtx.AppUser.UnderlyingDB().Statement.Context, + } { + if v := ctx.Value(key); v != value { + t.Errorf("get value from context fail, expect %q, got %q", value, v) + } + } +} + +func Test_Transaction(t *testing.T) { + query := Use(_gen_test_db) + if !query.Available() { + t.Errorf("query Use(_gen_test_db) fail: query.Available() == false") + } + + err := query.Transaction(func(tx *Query) error { return nil }) + if err != nil { + t.Errorf("query.Transaction execute fail: %s", err) + } + + tx := query.Begin() + + err = tx.SavePoint("point") + if err != nil { + t.Errorf("query tx SavePoint fail: %s", err) + } + err = tx.RollbackTo("point") + if err != nil { + t.Errorf("query tx RollbackTo fail: %s", err) + } + err = tx.Commit() + if err != nil { + t.Errorf("query tx Commit fail: %s", err) + } + + err = query.Begin().Rollback() + if err != nil { + t.Errorf("query tx Rollback fail: %s", err) + } +} diff --git a/app/auth_service/internal/gen/gen.yaml b/app/auth_service/internal/gen/gen.yaml new file mode 100644 index 0000000..31c4444 --- /dev/null +++ b/app/auth_service/internal/gen/gen.yaml @@ -0,0 +1,15 @@ +version: "0.1" +database: + dsn : "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local" + db : "mysql" + tables : + - "app_user" + - "app_account" + outPath : "./dao/query" + outFile : "" + withUnitTest : true + modelPkgName : "model" + fieldNullable : true + fieldWithIndexTag : true + fieldWithTypeTag : true + fieldSignable : true \ No newline at end of file diff --git a/app/auth_service/internal/logic/code2_session_logic.go b/app/auth_service/internal/logic/code2_session_logic.go index b492b9a..a13c392 100644 --- a/app/auth_service/internal/logic/code2_session_logic.go +++ b/app/auth_service/internal/logic/code2_session_logic.go @@ -4,6 +4,7 @@ import ( "context" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management" "github.com/zeromicro/go-zero/core/logx" ) @@ -23,6 +24,7 @@ func NewCode2SessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Code } func (l *Code2SessionLogic) Code2Session(in *auth_service.Code2SessionRequest) (*auth_service.Code2SessionResponse, error) { + //获取cli,调用抖音或者微信api cli, err := l.svcCtx.Cli.Get(in.AppId) if err != nil { return nil, err @@ -31,8 +33,33 @@ func (l *Code2SessionLogic) Code2Session(in *auth_service.Code2SessionRequest) ( if err != nil { return nil, err } + + //获取appId + ac := l.svcCtx.Query.AppAccount + acModel, err := ac.WithContext(l.ctx).Where(ac.AppID.Eq(in.AppId)).First() + if err != nil { + return nil, err + } + + //获取用户id + au := l.svcCtx.Query.AppUser + auModel, err := au.WithContext(l.ctx).Where(au.AppAccountID.Eq(acModel.ID), au.Openid.Eq(res.OpenID)).FirstOrCreate() + if err != nil { + return nil, err + } + + //如果没有用户id,则创建一个空用户 + if auModel.UserID == nil { + userId, err := l.svcCtx.UserManagerClient.CreateEmptyUser(l.ctx, &user_management.Empty{}) + if err != nil { + return nil, err + } + auModel.UserID = &userId.UserId + } + return &auth_service.Code2SessionResponse{ OpenId: res.OpenID, UnionId: res.UnionID, + UserId: *auModel.UserID, }, nil } diff --git a/app/auth_service/internal/server/auth_service_server.go b/app/auth_service/internal/server/auth_service_server.go index 07fe9f0..52dba28 100644 --- a/app/auth_service/internal/server/auth_service_server.go +++ b/app/auth_service/internal/server/auth_service_server.go @@ -6,14 +6,15 @@ package server import ( "context" - auth_service2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service" - logic2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/logic" + + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/auth_service" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/logic" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/svc" ) type AuthServiceServer struct { svcCtx *svc.ServiceContext - auth_service2.UnimplementedAuthServiceServer + auth_service.UnimplementedAuthServiceServer } func NewAuthServiceServer(svcCtx *svc.ServiceContext) *AuthServiceServer { @@ -22,17 +23,17 @@ func NewAuthServiceServer(svcCtx *svc.ServiceContext) *AuthServiceServer { } } -func (s *AuthServiceServer) Ping(ctx context.Context, in *auth_service2.Request) (*auth_service2.Response, error) { - l := logic2.NewPingLogic(ctx, s.svcCtx) +func (s *AuthServiceServer) Ping(ctx context.Context, in *auth_service.Request) (*auth_service.Response, error) { + l := logic.NewPingLogic(ctx, s.svcCtx) return l.Ping(in) } -func (s *AuthServiceServer) Code2Session(ctx context.Context, in *auth_service2.Code2SessionRequest) (*auth_service2.Code2SessionResponse, error) { - l := logic2.NewCode2SessionLogic(ctx, s.svcCtx) +func (s *AuthServiceServer) Code2Session(ctx context.Context, in *auth_service.Code2SessionRequest) (*auth_service.Code2SessionResponse, error) { + l := logic.NewCode2SessionLogic(ctx, s.svcCtx) return l.Code2Session(in) } -func (s *AuthServiceServer) GetAccessToken(ctx context.Context, in *auth_service2.GetAccessTokenRequest) (*auth_service2.GetAccessTokenResponse, error) { - l := logic2.NewGetAccessTokenLogic(ctx, s.svcCtx) +func (s *AuthServiceServer) GetAccessToken(ctx context.Context, in *auth_service.GetAccessTokenRequest) (*auth_service.GetAccessTokenResponse, error) { + l := logic.NewGetAccessTokenLogic(ctx, s.svcCtx) return l.GetAccessToken(in) } diff --git a/app/auth_service/internal/svc/service_context.go b/app/auth_service/internal/svc/service_context.go index 6a0534b..62309a8 100644 --- a/app/auth_service/internal/svc/service_context.go +++ b/app/auth_service/internal/svc/service_context.go @@ -2,28 +2,113 @@ package svc import ( "context" - "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/config" + "encoding/json" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/gen/dao/query" cli2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/pkg" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management_client" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/config" + "github.com/silenceper/wechat/v2/cache" redisCache "github.com/silenceper/wechat/v2/cache" + "github.com/spf13/viper" + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/core/discov" + "github.com/zeromicro/go-zero/zrpc" + clientv3 "go.etcd.io/etcd/client/v3" ) type ServiceContext struct { - Config config.Config - Cli cli2.Helper + Config config.Config + Cli cli2.Helper + UserManagerClient user_management_client.UserManagement + Query *query.Query } func NewServiceContext(c config.Config) *ServiceContext { - return &ServiceContext{ + + svc := &ServiceContext{ Config: c, } + + clientConf := zrpc.RpcClientConf{} + err := conf.FillDefault(&clientConf) // 填充默认值,比如 trace 透传等,参考服务配置说明 + if err != nil { + panic(err) + } + clientConf.Token = "user_management.rpc.key" + clientConf.App = "user_management.rpc" + clientConf.Etcd = discov.EtcdConf{ // 通过 etcd 服务发现 + Hosts: []string{viper.GetString(config.EtcdAddrKey)}, + Key: "user_management.rpc", + } + + svc.UserManagerClient = user_management.NewUserManagementClient(zrpc.MustNewClient(clientConf).Conn()) + + svc.InitClient() + + return svc } -func (svc *ServiceContext) InitClient(c config.Config) { +type AppData struct { + AppId string `json:"appId"` + AppSecret string `json:"appSecret"` + Type string `json:"type"` +} - dwCache := redisCache.NewRedis(context.Background(), &redisCache.RedisOpts{Host: c.Redis.Host}) +type AppDataList []AppData +const AppDataWatchKey = "/youtu/appData" + +func (svc *ServiceContext) InitClient() { + + dwCache := redisCache.NewRedis(context.Background(), &redisCache.RedisOpts{Host: svc.Config.Redis[0].Host}) + + cli, err := clientv3.NewFromURL(viper.GetString(config.EtcdAddrKey)) + if err != nil { + panic(err) + } + + res, err := cli.Get(context.TODO(), AppDataWatchKey) + if err != nil { + panic(err) + } + + var appDataArr AppDataList + + for _, kv := range res.Kvs { + var arr AppDataList + err = json.Unmarshal(kv.Value, &arr) + if err != nil { + panic(err) + } + appDataArr = append(appDataArr, arr...) + } + + svc.SaveDW(appDataArr, dwCache) + + go func() { + ch := cli.Watch(context.Background(), AppDataWatchKey) + //从通道中尝试取值(监视的信息) + for res := range ch { + var appDataArr AppDataList + for _, evt := range res.Events { + var arr AppDataList + err = json.Unmarshal(evt.Kv.Value, &arr) + if err != nil { + panic(err) //todo logger + } + appDataArr = append(appDataArr, arr...) + } + svc.SaveDW(appDataArr, dwCache) + } + }() + +} + +func (svc *ServiceContext) SaveDW(arr []AppData, dwCache cache.Cache) { + svc.Cli.Clear() //配置小程序cli(抖音&微信) - for _, v := range c.AppData { + for _, v := range arr { var c cli2.DWClient switch v.Type { case cli2.DouyinClientType: diff --git a/app/user_management/internal/logic/create_empty_user_logic.go b/app/user_management/internal/logic/create_empty_user_logic.go new file mode 100644 index 0000000..ecf9a70 --- /dev/null +++ b/app/user_management/internal/logic/create_empty_user_logic.go @@ -0,0 +1,39 @@ +package logic + +import ( + "context" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/gen/dao/model" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/svc" + "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CreateEmptyUserLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewCreateEmptyUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateEmptyUserLogic { + return &CreateEmptyUserLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *CreateEmptyUserLogic) CreateEmptyUser(_ *user_management.Empty) (*user_management.UserId, error) { + userId, err := l.svcCtx.IDGen.NextID() + if err != nil { + return nil, err + } + err = l.svcCtx.Query.User.WithContext(l.ctx).Create(&model.User{ + ID: userId, + }) + if err != nil { + return nil, err + } + + return &user_management.UserId{UserId: userId}, nil +} diff --git a/app/user_management/internal/logic/create_user_logic.go b/app/user_management/internal/logic/create_user_logic.go index 1096255..1788c19 100644 --- a/app/user_management/internal/logic/create_user_logic.go +++ b/app/user_management/internal/logic/create_user_logic.go @@ -24,7 +24,7 @@ func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create } // CreateUser 创建用户 -func (l *CreateUserLogic) CreateUser(in *user_management.CreateUserRequest) (res *user_management.CreateUserResponse, err error) { +func (l *CreateUserLogic) CreateUser(in *user_management.CreateUserRequest) (res *user_management.UserId, err error) { user := l.svcCtx.Query.User userModel := model.User{ Nickname: in.Nickname, @@ -39,5 +39,5 @@ func (l *CreateUserLogic) CreateUser(in *user_management.CreateUserRequest) (res if err != nil { return nil, err } - return &user_management.CreateUserResponse{UserId: userModel.ID}, nil + return &user_management.UserId{UserId: userModel.ID}, nil } diff --git a/app/user_management/internal/server/user_management_server.go b/app/user_management/internal/server/user_management_server.go index 48e9179..e50980d 100644 --- a/app/user_management/internal/server/user_management_server.go +++ b/app/user_management/internal/server/user_management_server.go @@ -35,7 +35,12 @@ func (s *UserManagementServer) SetUser(ctx context.Context, in *user_management. } // 获取用户或者创建用户 -func (s *UserManagementServer) CreateUser(ctx context.Context, in *user_management.CreateUserRequest) (*user_management.CreateUserResponse, error) { +func (s *UserManagementServer) CreateUser(ctx context.Context, in *user_management.CreateUserRequest) (*user_management.UserId, error) { l := logic.NewCreateUserLogic(ctx, s.svcCtx) return l.CreateUser(in) } + +func (s *UserManagementServer) CreateEmptyUser(ctx context.Context, in *user_management.Empty) (*user_management.UserId, error) { + l := logic.NewCreateEmptyUserLogic(ctx, s.svcCtx) + return l.CreateEmptyUser(in) +} diff --git a/app/user_management/user_management.go b/app/user_management/user_management.go index 8432eac..2dc8891 100644 --- a/app/user_management/user_management.go +++ b/app/user_management/user_management.go @@ -7,7 +7,6 @@ import ( "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/svc" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/config" - _ "github.com/spf13/viper/remote" "github.com/zeromicro/go-zero/core/service" "github.com/zeromicro/go-zero/zrpc" "google.golang.org/grpc" @@ -25,6 +24,8 @@ func main() { panic(err) } + c.RpcServerConf.Name = ServiceName + ".rpc" + ctx := svc.NewServiceContext(c) s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { diff --git a/app/user_management/user_management.proto b/app/user_management/user_management.proto index b8953ad..89c54d2 100644 --- a/app/user_management/user_management.proto +++ b/app/user_management/user_management.proto @@ -26,10 +26,12 @@ message CreateUserRequest{ string Avatar = 2; } -message CreateUserResponse{ +message UserId{ uint64 UserId = 1; } +message Empty {}//空结构体 + service user_management { rpc Ping(Request) returns(Response); @@ -37,5 +39,7 @@ service user_management { rpc SetUser (SetUserRequest) returns(SetUserResponse); //获取用户或者创建用户 - rpc CreateUser(CreateUserRequest) returns(CreateUserResponse); + rpc CreateUser(CreateUserRequest) returns(UserId); + + rpc CreateEmptyUser(Empty) returns(UserId); } diff --git a/app/user_management/user_management/user_management.pb.go b/app/user_management/user_management/user_management.pb.go index b59a6d7..65afca9 100644 --- a/app/user_management/user_management/user_management.pb.go +++ b/app/user_management/user_management/user_management.pb.go @@ -265,27 +265,27 @@ func (x *CreateUserRequest) GetAvatar() string { return "" } -type CreateUserResponse struct { +type UserId struct { state protoimpl.MessageState `protogen:"open.v1"` UserId uint64 `protobuf:"varint,1,opt,name=UserId,proto3" json:"UserId,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *CreateUserResponse) Reset() { - *x = CreateUserResponse{} +func (x *UserId) Reset() { + *x = UserId{} mi := &file_user_management_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *CreateUserResponse) String() string { +func (x *UserId) String() string { return protoimpl.X.MessageStringOf(x) } -func (*CreateUserResponse) ProtoMessage() {} +func (*UserId) ProtoMessage() {} -func (x *CreateUserResponse) ProtoReflect() protoreflect.Message { +func (x *UserId) ProtoReflect() protoreflect.Message { mi := &file_user_management_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -297,18 +297,54 @@ func (x *CreateUserResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use CreateUserResponse.ProtoReflect.Descriptor instead. -func (*CreateUserResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use UserId.ProtoReflect.Descriptor instead. +func (*UserId) Descriptor() ([]byte, []int) { return file_user_management_proto_rawDescGZIP(), []int{5} } -func (x *CreateUserResponse) GetUserId() uint64 { +func (x *UserId) GetUserId() uint64 { if x != nil { return x.UserId } return 0 } +type Empty struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Empty) Reset() { + *x = Empty{} + mi := &file_user_management_proto_msgTypes[6] + 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_user_management_proto_msgTypes[6] + if 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_user_management_proto_rawDescGZIP(), []int{6} +} + var File_user_management_proto protoreflect.FileDescriptor var file_user_management_proto_rawDesc = string([]byte{ @@ -332,27 +368,30 @@ var file_user_management_proto_rawDesc = string([]byte{ 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x41, - 0x76, 0x61, 0x74, 0x61, 0x72, 0x22, 0x2c, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, - 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x55, - 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x55, 0x73, 0x65, - 0x72, 0x49, 0x64, 0x32, 0xf3, 0x01, 0x0a, 0x0f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, - 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x3b, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, - 0x18, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, - 0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, - 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4c, 0x0a, 0x07, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x12, - 0x1f, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, - 0x74, 0x2e, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x20, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, - 0x6e, 0x74, 0x2e, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x55, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, - 0x12, 0x22, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, - 0x6e, 0x74, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, - 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, - 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x13, 0x5a, 0x11, 0x2e, 0x2f, 0x75, - 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x76, 0x61, 0x74, 0x61, 0x72, 0x22, 0x20, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, + 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x32, 0xab, 0x02, 0x0a, 0x0f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, + 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x3b, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x18, 0x2e, 0x75, + 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, + 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x4c, 0x0a, 0x07, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x12, 0x1f, 0x2e, 0x75, + 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, + 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, + 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, + 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x49, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x22, 0x2e, + 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x17, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, + 0x65, 0x6e, 0x74, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x42, 0x0a, 0x0f, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x55, 0x73, 0x65, 0x72, 0x12, 0x16, 0x2e, + 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x17, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, + 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x42, 0x13, + 0x5a, 0x11, 0x2e, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, + 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, }) var ( @@ -367,24 +406,27 @@ func file_user_management_proto_rawDescGZIP() []byte { return file_user_management_proto_rawDescData } -var file_user_management_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_user_management_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_user_management_proto_goTypes = []any{ - (*Request)(nil), // 0: user_management.Request - (*Response)(nil), // 1: user_management.Response - (*SetUserRequest)(nil), // 2: user_management.SetUserRequest - (*SetUserResponse)(nil), // 3: user_management.SetUserResponse - (*CreateUserRequest)(nil), // 4: user_management.CreateUserRequest - (*CreateUserResponse)(nil), // 5: user_management.CreateUserResponse + (*Request)(nil), // 0: user_management.Request + (*Response)(nil), // 1: user_management.Response + (*SetUserRequest)(nil), // 2: user_management.SetUserRequest + (*SetUserResponse)(nil), // 3: user_management.SetUserResponse + (*CreateUserRequest)(nil), // 4: user_management.CreateUserRequest + (*UserId)(nil), // 5: user_management.UserId + (*Empty)(nil), // 6: user_management.Empty } var file_user_management_proto_depIdxs = []int32{ 0, // 0: user_management.user_management.Ping:input_type -> user_management.Request 2, // 1: user_management.user_management.SetUser:input_type -> user_management.SetUserRequest 4, // 2: user_management.user_management.CreateUser:input_type -> user_management.CreateUserRequest - 1, // 3: user_management.user_management.Ping:output_type -> user_management.Response - 3, // 4: user_management.user_management.SetUser:output_type -> user_management.SetUserResponse - 5, // 5: user_management.user_management.CreateUser:output_type -> user_management.CreateUserResponse - 3, // [3:6] is the sub-list for method output_type - 0, // [0:3] is the sub-list for method input_type + 6, // 3: user_management.user_management.CreateEmptyUser:input_type -> user_management.Empty + 1, // 4: user_management.user_management.Ping:output_type -> user_management.Response + 3, // 5: user_management.user_management.SetUser:output_type -> user_management.SetUserResponse + 5, // 6: user_management.user_management.CreateUser:output_type -> user_management.UserId + 5, // 7: user_management.user_management.CreateEmptyUser:output_type -> user_management.UserId + 4, // [4:8] is the sub-list for method output_type + 0, // [0:4] 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 @@ -401,7 +443,7 @@ func file_user_management_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_management_proto_rawDesc), len(file_user_management_proto_rawDesc)), NumEnums: 0, - NumMessages: 6, + NumMessages: 7, NumExtensions: 0, NumServices: 1, }, diff --git a/app/user_management/user_management/user_management_grpc.pb.go b/app/user_management/user_management/user_management_grpc.pb.go index ffe1713..ccb5676 100644 --- a/app/user_management/user_management/user_management_grpc.pb.go +++ b/app/user_management/user_management/user_management_grpc.pb.go @@ -19,9 +19,10 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - UserManagement_Ping_FullMethodName = "/user_management.user_management/Ping" - UserManagement_SetUser_FullMethodName = "/user_management.user_management/SetUser" - UserManagement_CreateUser_FullMethodName = "/user_management.user_management/CreateUser" + UserManagement_Ping_FullMethodName = "/user_management.user_management/Ping" + UserManagement_SetUser_FullMethodName = "/user_management.user_management/SetUser" + UserManagement_CreateUser_FullMethodName = "/user_management.user_management/CreateUser" + UserManagement_CreateEmptyUser_FullMethodName = "/user_management.user_management/CreateEmptyUser" ) // UserManagementClient is the client API for UserManagement service. @@ -32,7 +33,8 @@ type UserManagementClient interface { // 设置用户信息 SetUser(ctx context.Context, in *SetUserRequest, opts ...grpc.CallOption) (*SetUserResponse, error) // 获取用户或者创建用户 - CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error) + CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error) + CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error) } type userManagementClient struct { @@ -63,9 +65,9 @@ func (c *userManagementClient) SetUser(ctx context.Context, in *SetUserRequest, return out, nil } -func (c *userManagementClient) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error) { +func (c *userManagementClient) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(CreateUserResponse) + out := new(UserId) err := c.cc.Invoke(ctx, UserManagement_CreateUser_FullMethodName, in, out, cOpts...) if err != nil { return nil, err @@ -73,6 +75,16 @@ func (c *userManagementClient) CreateUser(ctx context.Context, in *CreateUserReq return out, nil } +func (c *userManagementClient) CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UserId) + err := c.cc.Invoke(ctx, UserManagement_CreateEmptyUser_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // UserManagementServer is the server API for UserManagement service. // All implementations must embed UnimplementedUserManagementServer // for forward compatibility. @@ -81,7 +93,8 @@ type UserManagementServer interface { // 设置用户信息 SetUser(context.Context, *SetUserRequest) (*SetUserResponse, error) // 获取用户或者创建用户 - CreateUser(context.Context, *CreateUserRequest) (*CreateUserResponse, error) + CreateUser(context.Context, *CreateUserRequest) (*UserId, error) + CreateEmptyUser(context.Context, *Empty) (*UserId, error) mustEmbedUnimplementedUserManagementServer() } @@ -98,9 +111,12 @@ func (UnimplementedUserManagementServer) Ping(context.Context, *Request) (*Respo func (UnimplementedUserManagementServer) SetUser(context.Context, *SetUserRequest) (*SetUserResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SetUser not implemented") } -func (UnimplementedUserManagementServer) CreateUser(context.Context, *CreateUserRequest) (*CreateUserResponse, error) { +func (UnimplementedUserManagementServer) CreateUser(context.Context, *CreateUserRequest) (*UserId, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateUser not implemented") } +func (UnimplementedUserManagementServer) CreateEmptyUser(context.Context, *Empty) (*UserId, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateEmptyUser not implemented") +} func (UnimplementedUserManagementServer) mustEmbedUnimplementedUserManagementServer() {} func (UnimplementedUserManagementServer) testEmbeddedByValue() {} @@ -176,6 +192,24 @@ func _UserManagement_CreateUser_Handler(srv interface{}, ctx context.Context, de return interceptor(ctx, in, info, handler) } +func _UserManagement_CreateEmptyUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserManagementServer).CreateEmptyUser(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: UserManagement_CreateEmptyUser_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserManagementServer).CreateEmptyUser(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + // UserManagement_ServiceDesc is the grpc.ServiceDesc for UserManagement service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -195,6 +229,10 @@ var UserManagement_ServiceDesc = grpc.ServiceDesc{ MethodName: "CreateUser", Handler: _UserManagement_CreateUser_Handler, }, + { + MethodName: "CreateEmptyUser", + Handler: _UserManagement_CreateEmptyUser_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "user_management.proto", diff --git a/app/user_management/user_management_client/user_management.go b/app/user_management/user_management_client/user_management.go index 22b50c2..00f6e31 100644 --- a/app/user_management/user_management_client/user_management.go +++ b/app/user_management/user_management_client/user_management.go @@ -14,19 +14,21 @@ import ( ) type ( - CreateUserRequest = user_management.CreateUserRequest - CreateUserResponse = user_management.CreateUserResponse - Request = user_management.Request - Response = user_management.Response - SetUserRequest = user_management.SetUserRequest - SetUserResponse = user_management.SetUserResponse + CreateUserRequest = user_management.CreateUserRequest + Empty = user_management.Empty + Request = user_management.Request + Response = user_management.Response + SetUserRequest = user_management.SetUserRequest + SetUserResponse = user_management.SetUserResponse + UserId = user_management.UserId UserManagement interface { Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) // 设置用户信息 SetUser(ctx context.Context, in *SetUserRequest, opts ...grpc.CallOption) (*SetUserResponse, error) // 获取用户或者创建用户 - CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error) + CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error) + CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error) } defaultUserManagement struct { @@ -52,7 +54,12 @@ func (m *defaultUserManagement) SetUser(ctx context.Context, in *SetUserRequest, } // 获取用户或者创建用户 -func (m *defaultUserManagement) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error) { +func (m *defaultUserManagement) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error) { client := user_management.NewUserManagementClient(m.cli.Conn()) return client.CreateUser(ctx, in, opts...) } + +func (m *defaultUserManagement) CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error) { + client := user_management.NewUserManagementClient(m.cli.Conn()) + return client.CreateEmptyUser(ctx, in, opts...) +} diff --git a/pkg/config/get_config.go b/pkg/config/get_config.go index bfeccb6..23f1e1a 100644 --- a/pkg/config/get_config.go +++ b/pkg/config/get_config.go @@ -2,6 +2,7 @@ package config import ( "github.com/spf13/viper" + _ "github.com/spf13/viper/remote" "github.com/zeromicro/go-zero/zrpc" ) @@ -33,7 +34,7 @@ type Config struct { } func init() { - viper.SetDefault(EtcdAddrKey, "http://192.168.0.47:2379") + viper.SetDefault(EtcdAddrKey, "192.168.0.47:2379") viper.SetDefault(TypeKey, TypeEtcd) } diff --git a/pkg/config/get_config_test.go b/pkg/config/get_config_test.go index 6853544..5e2c39f 100644 --- a/pkg/config/get_config_test.go +++ b/pkg/config/get_config_test.go @@ -30,10 +30,12 @@ func TestGetConfig(t *testing.T) { func TestGenConfig(t *testing.T) { var c Config - c.RpcServerConf.ListenOn = "0.0.0.0:8080" + c.RpcServerConf.ListenOn = "0.0.0.0:8081" c.Mode = "dev" c.Mysql = "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local" c.Redis = []Redis{{Host: "192.168.0.47:2379:6379"}} + c.RpcServerConf.Etcd.Hosts = append(c.RpcServerConf.Etcd.Hosts, "192.168.0.47:2379") + c.RpcServerConf.Etcd.Key = "user_management.rpc" b, err := json.Marshal(c) if err != nil { t.Fatal(err)