db库
This commit is contained in:
parent
45e1fd8a80
commit
560d4e783e
|
@ -0,0 +1,312 @@
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
// The following code is automatically generated by the mongo-dao-generator tool.
|
||||||
|
// Please do not modify this code manually to avoid being overwritten in the next generation.
|
||||||
|
// For more tool details, please click the link to view https://github.com/dobyte/mongo-dao-generator
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
modelpkg "mongo.games.com/game/db/model"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserFilterFunc func(cols *UserColumns) interface{}
|
||||||
|
type UserUpdateFunc func(cols *UserColumns) interface{}
|
||||||
|
type UserPipelineFunc func(cols *UserColumns) interface{}
|
||||||
|
type UserCountOptionsFunc func(cols *UserColumns) *options.CountOptions
|
||||||
|
type UserAggregateOptionsFunc func(cols *UserColumns) *options.AggregateOptions
|
||||||
|
type UserFindOneOptionsFunc func(cols *UserColumns) *options.FindOneOptions
|
||||||
|
type UserFindManyOptionsFunc func(cols *UserColumns) *options.FindOptions
|
||||||
|
type UserUpdateOptionsFunc func(cols *UserColumns) *options.UpdateOptions
|
||||||
|
type UserDeleteOptionsFunc func(cols *UserColumns) *options.DeleteOptions
|
||||||
|
type UserInsertOneOptionsFunc func(cols *UserColumns) *options.InsertOneOptions
|
||||||
|
type UserInsertManyOptionsFunc func(cols *UserColumns) *options.InsertManyOptions
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
Columns *UserColumns
|
||||||
|
Database *mongo.Database
|
||||||
|
Collection *mongo.Collection
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserColumns struct {
|
||||||
|
ID string
|
||||||
|
Account string // 用户账号
|
||||||
|
Password string // 用户密码
|
||||||
|
Salt string // 密码
|
||||||
|
Mobile string // 用户手机
|
||||||
|
Email string // 用户邮箱
|
||||||
|
Nickname string // 用户昵称
|
||||||
|
Signature string // 用户签名
|
||||||
|
Level string // 用户等级
|
||||||
|
Experience string // 用户经验
|
||||||
|
Coin string // 用户金币
|
||||||
|
DeviceID string // 设备ID
|
||||||
|
RegisterIP string // 注册IP
|
||||||
|
RegisterTime string // 注册时间
|
||||||
|
LastLoginIP string // 最近登录IP
|
||||||
|
LastLoginTime string // 最近登录时间
|
||||||
|
}
|
||||||
|
|
||||||
|
var userColumns = &UserColumns{
|
||||||
|
ID: "_id",
|
||||||
|
Account: "account", // 用户账号
|
||||||
|
Password: "password", // 用户密码
|
||||||
|
Salt: "salt", // 密码
|
||||||
|
Mobile: "mobile", // 用户手机
|
||||||
|
Email: "email", // 用户邮箱
|
||||||
|
Nickname: "nickname", // 用户昵称
|
||||||
|
Signature: "signature", // 用户签名
|
||||||
|
Level: "level", // 用户等级
|
||||||
|
Experience: "experience", // 用户经验
|
||||||
|
Coin: "coin", // 用户金币
|
||||||
|
DeviceID: "device_id", // 设备ID
|
||||||
|
RegisterIP: "register_ip", // 注册IP
|
||||||
|
RegisterTime: "register_time", // 注册时间
|
||||||
|
LastLoginIP: "last_login_ip", // 最近登录IP
|
||||||
|
LastLoginTime: "last_login_time", // 最近登录时间
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUser(db *mongo.Database) *User {
|
||||||
|
return &User{
|
||||||
|
Columns: userColumns,
|
||||||
|
Database: db,
|
||||||
|
Collection: db.Collection("user"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the number of documents in the collection.
|
||||||
|
func (dao *User) Count(ctx context.Context, filterFunc UserFilterFunc, optionsFunc ...UserCountOptionsFunc) (int64, error) {
|
||||||
|
var (
|
||||||
|
opts *options.CountOptions
|
||||||
|
filter = filterFunc(dao.Columns)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.Collection.CountDocuments(ctx, filter, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate executes an aggregate command against the collection and returns a cursor over the resulting documents.
|
||||||
|
func (dao *User) Aggregate(ctx context.Context, pipelineFunc UserPipelineFunc, optionsFunc ...UserAggregateOptionsFunc) (*mongo.Cursor, error) {
|
||||||
|
var (
|
||||||
|
opts *options.AggregateOptions
|
||||||
|
pipeline = pipelineFunc(dao.Columns)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.Collection.Aggregate(ctx, pipeline, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InsertOne executes an insert command to insert a single document into the collection.
|
||||||
|
func (dao *User) InsertOne(ctx context.Context, model *modelpkg.User, optionsFunc ...UserInsertOneOptionsFunc) (*mongo.InsertOneResult, error) {
|
||||||
|
if model == nil {
|
||||||
|
return nil, errors.New("model is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := dao.autofill(ctx, model); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var opts *options.InsertOneOptions
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.Collection.InsertOne(ctx, model, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InsertMany executes an insert command to insert multiple documents into the collection.
|
||||||
|
func (dao *User) InsertMany(ctx context.Context, models []*modelpkg.User, optionsFunc ...UserInsertManyOptionsFunc) (*mongo.InsertManyResult, error) {
|
||||||
|
if len(models) == 0 {
|
||||||
|
return nil, errors.New("models is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
documents := make([]interface{}, 0, len(models))
|
||||||
|
for i := range models {
|
||||||
|
model := models[i]
|
||||||
|
if err := dao.autofill(ctx, model); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
documents = append(documents, model)
|
||||||
|
}
|
||||||
|
|
||||||
|
var opts *options.InsertManyOptions
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.Collection.InsertMany(ctx, documents, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne executes an update command to update at most one document in the collection.
|
||||||
|
func (dao *User) UpdateOne(ctx context.Context, filterFunc UserFilterFunc, updateFunc UserUpdateFunc, optionsFunc ...UserUpdateOptionsFunc) (*mongo.UpdateResult, error) {
|
||||||
|
var (
|
||||||
|
opts *options.UpdateOptions
|
||||||
|
filter = filterFunc(dao.Columns)
|
||||||
|
update = updateFunc(dao.Columns)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.Collection.UpdateOne(ctx, filter, update, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneByID executes an update command to update at most one document in the collection.
|
||||||
|
func (dao *User) UpdateOneByID(ctx context.Context, id string, updateFunc UserUpdateFunc, optionsFunc ...UserUpdateOptionsFunc) (*mongo.UpdateResult, error) {
|
||||||
|
objectID, err := primitive.ObjectIDFromHex(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.UpdateOne(ctx, func(cols *UserColumns) interface{} {
|
||||||
|
return bson.M{"_id": objectID}
|
||||||
|
}, updateFunc, optionsFunc...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMany executes an update command to update documents in the collection.
|
||||||
|
func (dao *User) UpdateMany(ctx context.Context, filterFunc UserFilterFunc, updateFunc UserUpdateFunc, optionsFunc ...UserUpdateOptionsFunc) (*mongo.UpdateResult, error) {
|
||||||
|
var (
|
||||||
|
opts *options.UpdateOptions
|
||||||
|
filter = filterFunc(dao.Columns)
|
||||||
|
update = updateFunc(dao.Columns)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.Collection.UpdateMany(ctx, filter, update, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindOne executes a find command and returns a model for one document in the collection.
|
||||||
|
func (dao *User) FindOne(ctx context.Context, filterFunc UserFilterFunc, optionsFunc ...UserFindOneOptionsFunc) (*modelpkg.User, error) {
|
||||||
|
var (
|
||||||
|
opts *options.FindOneOptions
|
||||||
|
model = &modelpkg.User{}
|
||||||
|
filter = filterFunc(dao.Columns)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := dao.Collection.FindOne(ctx, filter, opts).Decode(model)
|
||||||
|
if err != nil {
|
||||||
|
if err == mongo.ErrNoDocuments {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return model, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindOneByID executes a find command and returns a model for one document in the collection.
|
||||||
|
func (dao *User) FindOneByID(ctx context.Context, id string, optionsFunc ...UserFindOneOptionsFunc) (*modelpkg.User, error) {
|
||||||
|
objectID, err := primitive.ObjectIDFromHex(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.FindOne(ctx, func(cols *UserColumns) interface{} {
|
||||||
|
return bson.M{"_id": objectID}
|
||||||
|
}, optionsFunc...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindMany executes a find command and returns many models the matching documents in the collection.
|
||||||
|
func (dao *User) FindMany(ctx context.Context, filterFunc UserFilterFunc, optionsFunc ...UserFindManyOptionsFunc) ([]*modelpkg.User, error) {
|
||||||
|
var (
|
||||||
|
opts *options.FindOptions
|
||||||
|
filter = filterFunc(dao.Columns)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
cur, err := dao.Collection.Find(ctx, filter, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
models := make([]*modelpkg.User, 0)
|
||||||
|
|
||||||
|
if err = cur.All(ctx, &models); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return models, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne executes a delete command to delete at most one document from the collection.
|
||||||
|
func (dao *User) DeleteOne(ctx context.Context, filterFunc UserFilterFunc, optionsFunc ...UserDeleteOptionsFunc) (*mongo.DeleteResult, error) {
|
||||||
|
var (
|
||||||
|
opts *options.DeleteOptions
|
||||||
|
filter = filterFunc(dao.Columns)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.Collection.DeleteOne(ctx, filter, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneByID executes a delete command to delete at most one document from the collection.
|
||||||
|
func (dao *User) DeleteOneByID(ctx context.Context, id string, optionsFunc ...UserDeleteOptionsFunc) (*mongo.DeleteResult, error) {
|
||||||
|
objectID, err := primitive.ObjectIDFromHex(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.DeleteOne(ctx, func(cols *UserColumns) interface{} {
|
||||||
|
return bson.M{"_id": objectID}
|
||||||
|
}, optionsFunc...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMany executes a delete command to delete documents from the collection.
|
||||||
|
func (dao *User) DeleteMany(ctx context.Context, filterFunc UserFilterFunc, optionsFunc ...UserDeleteOptionsFunc) (*mongo.DeleteResult, error) {
|
||||||
|
var (
|
||||||
|
opts *options.DeleteOptions
|
||||||
|
filter = filterFunc(dao.Columns)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(optionsFunc) > 0 {
|
||||||
|
opts = optionsFunc[0](dao.Columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.Collection.DeleteMany(ctx, filter, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// autofill when inserting data
|
||||||
|
func (dao *User) autofill(ctx context.Context, model *modelpkg.User) error {
|
||||||
|
if model.ID.IsZero() {
|
||||||
|
model.ID = primitive.NewObjectID()
|
||||||
|
}
|
||||||
|
|
||||||
|
if model.RegisterTime == 0 {
|
||||||
|
model.RegisterTime = primitive.NewDateTimeFromTime(time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
if model.LastLoginTime == 0 {
|
||||||
|
model.LastLoginTime = primitive.NewDateTimeFromTime(time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"mongo.games.com/game/db/dao/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserColumns = internal.UserColumns
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
*internal.User
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUser(db *mongo.Database, c *mongo.Collection) *User {
|
||||||
|
v := internal.NewUser(nil)
|
||||||
|
v.Database = db
|
||||||
|
v.Collection = c
|
||||||
|
panic("创建索引")
|
||||||
|
//c.Indexes().CreateOne()
|
||||||
|
//c.Indexes().CreateMany()
|
||||||
|
return &User{User: v}
|
||||||
|
}
|
36
db/export.go
36
db/export.go
|
@ -1,36 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"mongo.games.com/goserver/core/logger"
|
|
||||||
)
|
|
||||||
|
|
||||||
var GrpcServer *grpc.Server
|
|
||||||
var GrpcClientConn *grpc.ClientConn
|
|
||||||
|
|
||||||
func RunGrpcServer() {
|
|
||||||
GrpcServer = grpc.NewServer()
|
|
||||||
registerGrpcServer()
|
|
||||||
ln, err := net.Listen("tcp", ":8899")
|
|
||||||
if err != nil {
|
|
||||||
panic(errors.New("db grpc failed to listen: " + err.Error()))
|
|
||||||
}
|
|
||||||
|
|
||||||
err = GrpcServer.Serve(ln)
|
|
||||||
if err != nil {
|
|
||||||
panic(errors.New("db grpc failed to serve: " + err.Error()))
|
|
||||||
}
|
|
||||||
logger.Logger.Infof("db grpc start success")
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGrpcClientConn() {
|
|
||||||
var err error
|
|
||||||
GrpcClientConn, err = grpc.NewClient("localhost:8899", grpc.WithInsecure())
|
|
||||||
if err != nil {
|
|
||||||
panic(errors.New("db grpc failed to dial: " + err.Error()))
|
|
||||||
}
|
|
||||||
registerGrpcClient()
|
|
||||||
}
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
mongoctl -model-dir=./model -model-names=User -dao-dir=./dao
|
||||||
|
protoc --proto_path=./proto --go_out=../../../ --go-grpc_out=../../../ ./proto/*.proto
|
|
@ -1,16 +0,0 @@
|
||||||
set work_path=%cd%
|
|
||||||
set proto_path=%work_path%\proto
|
|
||||||
set protoc=%work_path%\..\bin\protoc-3.19.4-win64\bin\protoc.exe
|
|
||||||
set protoc-gen-go-plugin-path="%work_path%\..\bin\protoc-gen-go.exe"
|
|
||||||
set protoc-gen-go-grpc-plugin-path="%work_path%\..\bin\protoc-gen-go-grpc.exe"
|
|
||||||
|
|
||||||
rem echo %protoc3%
|
|
||||||
cd %proto_path%
|
|
||||||
for /d %%s in (,*) do (
|
|
||||||
cd %%s
|
|
||||||
for %%b in (,*.proto) do (
|
|
||||||
%protoc% --proto_path=%GOPATH%\src\mongo.games.com\game\db\proto --proto_path=. --plugin=protoc-gen-go=%protoc-gen-go-plugin-path% --plugin=protoc-gen-go-grpc=%protoc-gen-go-grpc-plugin-path% --go_out=%GOPATH%\src --go-grpc_out=%GOPATH%\src %%b
|
|
||||||
)
|
|
||||||
cd ..
|
|
||||||
)
|
|
||||||
cd %work_path%
|
|
|
@ -1,34 +0,0 @@
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"mongo.games.com/goserver/core/logger"
|
|
||||||
|
|
||||||
"mongo.games.com/game/db/proto/lottery"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 竞技馆抽奖记录
|
|
||||||
|
|
||||||
type Lottery struct {
|
|
||||||
Ts int64 // 中奖时间
|
|
||||||
SnId int32 // 玩家id
|
|
||||||
Name string // 玩家昵称
|
|
||||||
Number int64 // 中奖号码
|
|
||||||
Award map[int32]int64 // 奖品,key为奖品id,value为奖品数量
|
|
||||||
Video string // 视频地址
|
|
||||||
}
|
|
||||||
|
|
||||||
type LotteryServer struct {
|
|
||||||
lottery.UnimplementedLotteryServerServer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Lottery) Save(ctx context.Context, req *lottery.SaveReq) (*lottery.SaveRsp, error) {
|
|
||||||
logger.Logger.Infof("Lottery Save: %v", req)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Lottery) Find(ctx context.Context, req *lottery.FindReq) (*lottery.FindRsp, error) {
|
|
||||||
logger.Logger.Infof("Lottery Find: %v", req)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate mongoctl -model-dir=. -model-names=User -dao-dir=../dao
|
||||||
|
type User struct {
|
||||||
|
ID primitive.ObjectID `bson:"_id" gen:"autoFill"`
|
||||||
|
Account string `bson:"account"` // 用户账号
|
||||||
|
Password string `bson:"password"` // 用户密码
|
||||||
|
Salt string `bson:"salt"` // 密码
|
||||||
|
Mobile string `bson:"mobile"` // 用户手机
|
||||||
|
Email string `bson:"email"` // 用户邮箱
|
||||||
|
Nickname string `bson:"nickname"` // 用户昵称
|
||||||
|
Signature string `bson:"signature"` // 用户签名
|
||||||
|
Level int `bson:"level"` // 用户等级
|
||||||
|
Experience int `bson:"experience"` // 用户经验
|
||||||
|
Coin int `bson:"coin"` // 用户金币
|
||||||
|
DeviceID string `bson:"device_id"` // 设备ID
|
||||||
|
RegisterIP string `bson:"register_ip"` // 注册IP
|
||||||
|
RegisterTime primitive.DateTime `bson:"register_time" gen:"autoFill"` // 注册时间
|
||||||
|
LastLoginIP string `bson:"last_login_ip"` // 最近登录IP
|
||||||
|
LastLoginTime primitive.DateTime `bson:"last_login_time" gen:"autoFill"` // 最近登录时间
|
||||||
|
}
|
|
@ -1,448 +0,0 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
|
||||||
// versions:
|
|
||||||
// protoc-gen-go v1.27.1-devel
|
|
||||||
// protoc v3.19.4
|
|
||||||
// source: lottery.proto
|
|
||||||
|
|
||||||
package lottery
|
|
||||||
|
|
||||||
import (
|
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
public "mongo.games.com/game/db/proto/public"
|
|
||||||
reflect "reflect"
|
|
||||||
sync "sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Verify that this generated code is sufficiently up-to-date.
|
|
||||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
|
||||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
|
||||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
|
||||||
)
|
|
||||||
|
|
||||||
type Lottery struct {
|
|
||||||
state protoimpl.MessageState
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
|
|
||||||
Ts int64 `protobuf:"varint,1,opt,name=Ts,proto3" json:"Ts,omitempty"` // 中奖时间
|
|
||||||
SnId int32 `protobuf:"varint,2,opt,name=SnId,proto3" json:"SnId,omitempty"` // 玩家id
|
|
||||||
Name string `protobuf:"bytes,3,opt,name=Name,proto3" json:"Name,omitempty"` // 玩家昵称
|
|
||||||
Number int64 `protobuf:"varint,4,opt,name=Number,proto3" json:"Number,omitempty"` // 中奖号码
|
|
||||||
Award []*public.Item `protobuf:"bytes,5,rep,name=Award,proto3" json:"Award,omitempty"` // 奖品,key为奖品id,value为奖品数量
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Lottery) Reset() {
|
|
||||||
*x = Lottery{}
|
|
||||||
if protoimpl.UnsafeEnabled {
|
|
||||||
mi := &file_lottery_proto_msgTypes[0]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Lottery) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*Lottery) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *Lottery) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_lottery_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 Lottery.ProtoReflect.Descriptor instead.
|
|
||||||
func (*Lottery) Descriptor() ([]byte, []int) {
|
|
||||||
return file_lottery_proto_rawDescGZIP(), []int{0}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Lottery) GetTs() int64 {
|
|
||||||
if x != nil {
|
|
||||||
return x.Ts
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Lottery) GetSnId() int32 {
|
|
||||||
if x != nil {
|
|
||||||
return x.SnId
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Lottery) GetName() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Lottery) GetNumber() int64 {
|
|
||||||
if x != nil {
|
|
||||||
return x.Number
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Lottery) GetAward() []*public.Item {
|
|
||||||
if x != nil {
|
|
||||||
return x.Award
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//客户端发送给服务端
|
|
||||||
type SaveReq struct {
|
|
||||||
state protoimpl.MessageState
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
|
|
||||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *SaveReq) Reset() {
|
|
||||||
*x = SaveReq{}
|
|
||||||
if protoimpl.UnsafeEnabled {
|
|
||||||
mi := &file_lottery_proto_msgTypes[1]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *SaveReq) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*SaveReq) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *SaveReq) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_lottery_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 SaveReq.ProtoReflect.Descriptor instead.
|
|
||||||
func (*SaveReq) Descriptor() ([]byte, []int) {
|
|
||||||
return file_lottery_proto_rawDescGZIP(), []int{1}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *SaveReq) GetName() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
//服务端返回给客户端
|
|
||||||
type SaveRsp struct {
|
|
||||||
state protoimpl.MessageState
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
|
|
||||||
Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *SaveRsp) Reset() {
|
|
||||||
*x = SaveRsp{}
|
|
||||||
if protoimpl.UnsafeEnabled {
|
|
||||||
mi := &file_lottery_proto_msgTypes[2]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *SaveRsp) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*SaveRsp) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *SaveRsp) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_lottery_proto_msgTypes[2]
|
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
if ms.LoadMessageInfo() == nil {
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
return mi.MessageOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Use SaveRsp.ProtoReflect.Descriptor instead.
|
|
||||||
func (*SaveRsp) Descriptor() ([]byte, []int) {
|
|
||||||
return file_lottery_proto_rawDescGZIP(), []int{2}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *SaveRsp) GetMsg() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Msg
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
//客户端发送给服务端
|
|
||||||
type FindReq struct {
|
|
||||||
state protoimpl.MessageState
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
|
|
||||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *FindReq) Reset() {
|
|
||||||
*x = FindReq{}
|
|
||||||
if protoimpl.UnsafeEnabled {
|
|
||||||
mi := &file_lottery_proto_msgTypes[3]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *FindReq) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*FindReq) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *FindReq) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_lottery_proto_msgTypes[3]
|
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
if ms.LoadMessageInfo() == nil {
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
return mi.MessageOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Use FindReq.ProtoReflect.Descriptor instead.
|
|
||||||
func (*FindReq) Descriptor() ([]byte, []int) {
|
|
||||||
return file_lottery_proto_rawDescGZIP(), []int{3}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *FindReq) GetName() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Name
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
//服务端返回给客户端
|
|
||||||
type FindRsp struct {
|
|
||||||
state protoimpl.MessageState
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
|
|
||||||
Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *FindRsp) Reset() {
|
|
||||||
*x = FindRsp{}
|
|
||||||
if protoimpl.UnsafeEnabled {
|
|
||||||
mi := &file_lottery_proto_msgTypes[4]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *FindRsp) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*FindRsp) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *FindRsp) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_lottery_proto_msgTypes[4]
|
|
||||||
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 FindRsp.ProtoReflect.Descriptor instead.
|
|
||||||
func (*FindRsp) Descriptor() ([]byte, []int) {
|
|
||||||
return file_lottery_proto_rawDescGZIP(), []int{4}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *FindRsp) GetMsg() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Msg
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var File_lottery_proto protoreflect.FileDescriptor
|
|
||||||
|
|
||||||
var file_lottery_proto_rawDesc = []byte{
|
|
||||||
0x0a, 0x0d, 0x6c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
|
|
||||||
0x07, 0x6c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x1a, 0x13, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63,
|
|
||||||
0x2f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7d, 0x0a,
|
|
||||||
0x07, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x54, 0x73, 0x18, 0x01,
|
|
||||||
0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x54, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x53, 0x6e, 0x49, 0x64,
|
|
||||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x53, 0x6e, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04,
|
|
||||||
0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65,
|
|
||||||
0x12, 0x16, 0x0a, 0x06, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03,
|
|
||||||
0x52, 0x06, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x22, 0x0a, 0x05, 0x41, 0x77, 0x61, 0x72,
|
|
||||||
0x64, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63,
|
|
||||||
0x2e, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x05, 0x41, 0x77, 0x61, 0x72, 0x64, 0x22, 0x1d, 0x0a, 0x07,
|
|
||||||
0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
|
|
||||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x1b, 0x0a, 0x07, 0x53,
|
|
||||||
0x61, 0x76, 0x65, 0x52, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20,
|
|
||||||
0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x1d, 0x0a, 0x07, 0x46, 0x69, 0x6e, 0x64,
|
|
||||||
0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
|
|
||||||
0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x1b, 0x0a, 0x07, 0x46, 0x69, 0x6e, 0x64, 0x52,
|
|
||||||
0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
|
||||||
0x03, 0x6d, 0x73, 0x67, 0x32, 0x6b, 0x0a, 0x0d, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x53,
|
|
||||||
0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x2c, 0x0a, 0x04, 0x53, 0x61, 0x76, 0x65, 0x12, 0x10, 0x2e,
|
|
||||||
0x6c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x1a,
|
|
||||||
0x10, 0x2e, 0x6c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x73,
|
|
||||||
0x70, 0x22, 0x00, 0x12, 0x2c, 0x0a, 0x04, 0x46, 0x69, 0x6e, 0x64, 0x12, 0x10, 0x2e, 0x6c, 0x6f,
|
|
||||||
0x74, 0x74, 0x65, 0x72, 0x79, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x10, 0x2e,
|
|
||||||
0x6c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x52, 0x73, 0x70, 0x22,
|
|
||||||
0x00, 0x42, 0x27, 0x5a, 0x25, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73,
|
|
||||||
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x64, 0x62, 0x2f, 0x70, 0x72, 0x6f,
|
|
||||||
0x74, 0x6f, 0x2f, 0x6c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
|
||||||
0x6f, 0x33,
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
file_lottery_proto_rawDescOnce sync.Once
|
|
||||||
file_lottery_proto_rawDescData = file_lottery_proto_rawDesc
|
|
||||||
)
|
|
||||||
|
|
||||||
func file_lottery_proto_rawDescGZIP() []byte {
|
|
||||||
file_lottery_proto_rawDescOnce.Do(func() {
|
|
||||||
file_lottery_proto_rawDescData = protoimpl.X.CompressGZIP(file_lottery_proto_rawDescData)
|
|
||||||
})
|
|
||||||
return file_lottery_proto_rawDescData
|
|
||||||
}
|
|
||||||
|
|
||||||
var file_lottery_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
|
||||||
var file_lottery_proto_goTypes = []interface{}{
|
|
||||||
(*Lottery)(nil), // 0: lottery.Lottery
|
|
||||||
(*SaveReq)(nil), // 1: lottery.SaveReq
|
|
||||||
(*SaveRsp)(nil), // 2: lottery.SaveRsp
|
|
||||||
(*FindReq)(nil), // 3: lottery.FindReq
|
|
||||||
(*FindRsp)(nil), // 4: lottery.FindRsp
|
|
||||||
(*public.Item)(nil), // 5: public.Item
|
|
||||||
}
|
|
||||||
var file_lottery_proto_depIdxs = []int32{
|
|
||||||
5, // 0: lottery.Lottery.Award:type_name -> public.Item
|
|
||||||
1, // 1: lottery.LotteryServer.Save:input_type -> lottery.SaveReq
|
|
||||||
3, // 2: lottery.LotteryServer.Find:input_type -> lottery.FindReq
|
|
||||||
2, // 3: lottery.LotteryServer.Save:output_type -> lottery.SaveRsp
|
|
||||||
4, // 4: lottery.LotteryServer.Find:output_type -> lottery.FindRsp
|
|
||||||
3, // [3:5] is the sub-list for method output_type
|
|
||||||
1, // [1:3] is the sub-list for method input_type
|
|
||||||
1, // [1:1] is the sub-list for extension type_name
|
|
||||||
1, // [1:1] is the sub-list for extension extendee
|
|
||||||
0, // [0:1] is the sub-list for field type_name
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { file_lottery_proto_init() }
|
|
||||||
func file_lottery_proto_init() {
|
|
||||||
if File_lottery_proto != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !protoimpl.UnsafeEnabled {
|
|
||||||
file_lottery_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
|
||||||
switch v := v.(*Lottery); i {
|
|
||||||
case 0:
|
|
||||||
return &v.state
|
|
||||||
case 1:
|
|
||||||
return &v.sizeCache
|
|
||||||
case 2:
|
|
||||||
return &v.unknownFields
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file_lottery_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
|
||||||
switch v := v.(*SaveReq); i {
|
|
||||||
case 0:
|
|
||||||
return &v.state
|
|
||||||
case 1:
|
|
||||||
return &v.sizeCache
|
|
||||||
case 2:
|
|
||||||
return &v.unknownFields
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file_lottery_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
|
||||||
switch v := v.(*SaveRsp); i {
|
|
||||||
case 0:
|
|
||||||
return &v.state
|
|
||||||
case 1:
|
|
||||||
return &v.sizeCache
|
|
||||||
case 2:
|
|
||||||
return &v.unknownFields
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file_lottery_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
|
||||||
switch v := v.(*FindReq); i {
|
|
||||||
case 0:
|
|
||||||
return &v.state
|
|
||||||
case 1:
|
|
||||||
return &v.sizeCache
|
|
||||||
case 2:
|
|
||||||
return &v.unknownFields
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file_lottery_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
|
||||||
switch v := v.(*FindRsp); 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_lottery_proto_rawDesc,
|
|
||||||
NumEnums: 0,
|
|
||||||
NumMessages: 5,
|
|
||||||
NumExtensions: 0,
|
|
||||||
NumServices: 1,
|
|
||||||
},
|
|
||||||
GoTypes: file_lottery_proto_goTypes,
|
|
||||||
DependencyIndexes: file_lottery_proto_depIdxs,
|
|
||||||
MessageInfos: file_lottery_proto_msgTypes,
|
|
||||||
}.Build()
|
|
||||||
File_lottery_proto = out.File
|
|
||||||
file_lottery_proto_rawDesc = nil
|
|
||||||
file_lottery_proto_goTypes = nil
|
|
||||||
file_lottery_proto_depIdxs = nil
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
syntax = "proto3";
|
|
||||||
package lottery;
|
|
||||||
option go_package = "mongo.games.com/game/db/proto/lottery";
|
|
||||||
|
|
||||||
service LotteryServer {
|
|
||||||
rpc Save (SaveReq) returns (SaveRsp){}
|
|
||||||
rpc Find (FindReq) returns (FindRsp){}
|
|
||||||
}
|
|
||||||
|
|
||||||
//客户端发送给服务端
|
|
||||||
message SaveReq {
|
|
||||||
string name = 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
//服务端返回给客户端
|
|
||||||
message SaveRsp {
|
|
||||||
string msg = 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
//客户端发送给服务端
|
|
||||||
message FindReq {
|
|
||||||
string name = 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
//服务端返回给客户端
|
|
||||||
message FindRsp {
|
|
||||||
string msg = 1 ;
|
|
||||||
}
|
|
|
@ -1,146 +0,0 @@
|
||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
|
||||||
// versions:
|
|
||||||
// - protoc-gen-go-grpc v1.3.0
|
|
||||||
// - protoc v3.19.4
|
|
||||||
// source: lottery.proto
|
|
||||||
|
|
||||||
package lottery
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
const (
|
|
||||||
LotteryServer_Save_FullMethodName = "/lottery.LotteryServer/Save"
|
|
||||||
LotteryServer_Find_FullMethodName = "/lottery.LotteryServer/Find"
|
|
||||||
)
|
|
||||||
|
|
||||||
// LotteryServerClient is the client API for LotteryServer 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 LotteryServerClient interface {
|
|
||||||
Save(ctx context.Context, in *SaveReq, opts ...grpc.CallOption) (*SaveRsp, error)
|
|
||||||
Find(ctx context.Context, in *FindReq, opts ...grpc.CallOption) (*FindRsp, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type lotteryServerClient struct {
|
|
||||||
cc grpc.ClientConnInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewLotteryServerClient(cc grpc.ClientConnInterface) LotteryServerClient {
|
|
||||||
return &lotteryServerClient{cc}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *lotteryServerClient) Save(ctx context.Context, in *SaveReq, opts ...grpc.CallOption) (*SaveRsp, error) {
|
|
||||||
out := new(SaveRsp)
|
|
||||||
err := c.cc.Invoke(ctx, LotteryServer_Save_FullMethodName, in, out, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *lotteryServerClient) Find(ctx context.Context, in *FindReq, opts ...grpc.CallOption) (*FindRsp, error) {
|
|
||||||
out := new(FindRsp)
|
|
||||||
err := c.cc.Invoke(ctx, LotteryServer_Find_FullMethodName, in, out, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LotteryServerServer is the server API for LotteryServer service.
|
|
||||||
// All implementations must embed UnimplementedLotteryServerServer
|
|
||||||
// for forward compatibility
|
|
||||||
type LotteryServerServer interface {
|
|
||||||
Save(context.Context, *SaveReq) (*SaveRsp, error)
|
|
||||||
Find(context.Context, *FindReq) (*FindRsp, error)
|
|
||||||
mustEmbedUnimplementedLotteryServerServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnimplementedLotteryServerServer must be embedded to have forward compatible implementations.
|
|
||||||
type UnimplementedLotteryServerServer struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (UnimplementedLotteryServerServer) Save(context.Context, *SaveReq) (*SaveRsp, error) {
|
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Save not implemented")
|
|
||||||
}
|
|
||||||
func (UnimplementedLotteryServerServer) Find(context.Context, *FindReq) (*FindRsp, error) {
|
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Find not implemented")
|
|
||||||
}
|
|
||||||
func (UnimplementedLotteryServerServer) mustEmbedUnimplementedLotteryServerServer() {}
|
|
||||||
|
|
||||||
// UnsafeLotteryServerServer may be embedded to opt out of forward compatibility for this service.
|
|
||||||
// Use of this interface is not recommended, as added methods to LotteryServerServer will
|
|
||||||
// result in compilation errors.
|
|
||||||
type UnsafeLotteryServerServer interface {
|
|
||||||
mustEmbedUnimplementedLotteryServerServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterLotteryServerServer(s grpc.ServiceRegistrar, srv LotteryServerServer) {
|
|
||||||
s.RegisterService(&LotteryServer_ServiceDesc, srv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _LotteryServer_Save_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(SaveReq)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(LotteryServerServer).Save(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: LotteryServer_Save_FullMethodName,
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(LotteryServerServer).Save(ctx, req.(*SaveReq))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _LotteryServer_Find_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
||||||
in := new(FindReq)
|
|
||||||
if err := dec(in); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if interceptor == nil {
|
|
||||||
return srv.(LotteryServerServer).Find(ctx, in)
|
|
||||||
}
|
|
||||||
info := &grpc.UnaryServerInfo{
|
|
||||||
Server: srv,
|
|
||||||
FullMethod: LotteryServer_Find_FullMethodName,
|
|
||||||
}
|
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return srv.(LotteryServerServer).Find(ctx, req.(*FindReq))
|
|
||||||
}
|
|
||||||
return interceptor(ctx, in, info, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LotteryServer_ServiceDesc is the grpc.ServiceDesc for LotteryServer service.
|
|
||||||
// It's only intended for direct use with grpc.RegisterService,
|
|
||||||
// and not to be introspected or modified (even as a copy)
|
|
||||||
var LotteryServer_ServiceDesc = grpc.ServiceDesc{
|
|
||||||
ServiceName: "lottery.LotteryServer",
|
|
||||||
HandlerType: (*LotteryServerServer)(nil),
|
|
||||||
Methods: []grpc.MethodDesc{
|
|
||||||
{
|
|
||||||
MethodName: "Save",
|
|
||||||
Handler: _LotteryServer_Save_Handler,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MethodName: "Find",
|
|
||||||
Handler: _LotteryServer_Find_Handler,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Streams: []grpc.StreamDesc{},
|
|
||||||
Metadata: "lottery.proto",
|
|
||||||
}
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package user;
|
||||||
|
option go_package = "mongo.games.com/game/db/proto/user";
|
||||||
|
|
||||||
|
import "public.proto";
|
||||||
|
|
||||||
|
service UserServer {
|
||||||
|
rpc Save (SaveReq) returns (SaveRsp){}
|
||||||
|
}
|
||||||
|
|
||||||
|
//客户端发送给服务端
|
||||||
|
message SaveReq {
|
||||||
|
string Platform = 1;
|
||||||
|
string name = 2;
|
||||||
|
repeated public.Item Items = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
//服务端返回给客户端
|
||||||
|
message SaveRsp {
|
||||||
|
string msg = 1 ;
|
||||||
|
}
|
|
@ -0,0 +1,235 @@
|
||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// protoc-gen-go v1.27.1-devel
|
||||||
|
// protoc v3.19.4
|
||||||
|
// source: user.proto
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
public "mongo.games.com/game/db/proto/public"
|
||||||
|
reflect "reflect"
|
||||||
|
sync "sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Verify that this generated code is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||||
|
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||||
|
)
|
||||||
|
|
||||||
|
//客户端发送给服务端
|
||||||
|
type SaveReq struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
Platform string `protobuf:"bytes,1,opt,name=Platform,proto3" json:"Platform,omitempty"`
|
||||||
|
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
|
Items []*public.Item `protobuf:"bytes,3,rep,name=Items,proto3" json:"Items,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SaveReq) Reset() {
|
||||||
|
*x = SaveReq{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_user_proto_msgTypes[0]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SaveReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SaveReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SaveReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_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 SaveReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SaveReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SaveReq) GetPlatform() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Platform
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SaveReq) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SaveReq) GetItems() []*public.Item {
|
||||||
|
if x != nil {
|
||||||
|
return x.Items
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//服务端返回给客户端
|
||||||
|
type SaveRsp struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SaveRsp) Reset() {
|
||||||
|
*x = SaveRsp{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_user_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SaveRsp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SaveRsp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SaveRsp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_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 SaveRsp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SaveRsp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SaveRsp) GetMsg() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Msg
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var File_user_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
|
var file_user_proto_rawDesc = []byte{
|
||||||
|
0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x75, 0x73,
|
||||||
|
0x65, 0x72, 0x1a, 0x0c, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
|
0x22, 0x5d, 0x0a, 0x07, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x50,
|
||||||
|
0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50,
|
||||||
|
0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
|
||||||
|
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x22, 0x0a, 0x05, 0x49,
|
||||||
|
0x74, 0x65, 0x6d, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x75, 0x62,
|
||||||
|
0x6c, 0x69, 0x63, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x22,
|
||||||
|
0x1b, 0x0a, 0x07, 0x53, 0x61, 0x76, 0x65, 0x52, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73,
|
||||||
|
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x32, 0x34, 0x0a, 0x0a,
|
||||||
|
0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x26, 0x0a, 0x04, 0x53, 0x61,
|
||||||
|
0x76, 0x65, 0x12, 0x0d, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65,
|
||||||
|
0x71, 0x1a, 0x0d, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x73, 0x70,
|
||||||
|
0x22, 0x00, 0x42, 0x24, 0x5a, 0x22, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65,
|
||||||
|
0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x64, 0x62, 0x2f, 0x70, 0x72,
|
||||||
|
0x6f, 0x74, 0x6f, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
file_user_proto_rawDescOnce sync.Once
|
||||||
|
file_user_proto_rawDescData = file_user_proto_rawDesc
|
||||||
|
)
|
||||||
|
|
||||||
|
func file_user_proto_rawDescGZIP() []byte {
|
||||||
|
file_user_proto_rawDescOnce.Do(func() {
|
||||||
|
file_user_proto_rawDescData = protoimpl.X.CompressGZIP(file_user_proto_rawDescData)
|
||||||
|
})
|
||||||
|
return file_user_proto_rawDescData
|
||||||
|
}
|
||||||
|
|
||||||
|
var file_user_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||||
|
var file_user_proto_goTypes = []interface{}{
|
||||||
|
(*SaveReq)(nil), // 0: user.SaveReq
|
||||||
|
(*SaveRsp)(nil), // 1: user.SaveRsp
|
||||||
|
(*public.Item)(nil), // 2: public.Item
|
||||||
|
}
|
||||||
|
var file_user_proto_depIdxs = []int32{
|
||||||
|
2, // 0: user.SaveReq.Items:type_name -> public.Item
|
||||||
|
0, // 1: user.UserServer.Save:input_type -> user.SaveReq
|
||||||
|
1, // 2: user.UserServer.Save:output_type -> user.SaveRsp
|
||||||
|
2, // [2:3] is the sub-list for method output_type
|
||||||
|
1, // [1:2] is the sub-list for method input_type
|
||||||
|
1, // [1:1] is the sub-list for extension type_name
|
||||||
|
1, // [1:1] is the sub-list for extension extendee
|
||||||
|
0, // [0:1] is the sub-list for field type_name
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { file_user_proto_init() }
|
||||||
|
func file_user_proto_init() {
|
||||||
|
if File_user_proto != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !protoimpl.UnsafeEnabled {
|
||||||
|
file_user_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*SaveReq); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_user_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*SaveRsp); 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_user_proto_rawDesc,
|
||||||
|
NumEnums: 0,
|
||||||
|
NumMessages: 2,
|
||||||
|
NumExtensions: 0,
|
||||||
|
NumServices: 1,
|
||||||
|
},
|
||||||
|
GoTypes: file_user_proto_goTypes,
|
||||||
|
DependencyIndexes: file_user_proto_depIdxs,
|
||||||
|
MessageInfos: file_user_proto_msgTypes,
|
||||||
|
}.Build()
|
||||||
|
File_user_proto = out.File
|
||||||
|
file_user_proto_rawDesc = nil
|
||||||
|
file_user_proto_goTypes = nil
|
||||||
|
file_user_proto_depIdxs = nil
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.3.0
|
||||||
|
// - protoc v3.19.4
|
||||||
|
// source: user.proto
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
const (
|
||||||
|
UserServer_Save_FullMethodName = "/user.UserServer/Save"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserServerClient is the client API for UserServer 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 UserServerClient interface {
|
||||||
|
Save(ctx context.Context, in *SaveReq, opts ...grpc.CallOption) (*SaveRsp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type userServerClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserServerClient(cc grpc.ClientConnInterface) UserServerClient {
|
||||||
|
return &userServerClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *userServerClient) Save(ctx context.Context, in *SaveReq, opts ...grpc.CallOption) (*SaveRsp, error) {
|
||||||
|
out := new(SaveRsp)
|
||||||
|
err := c.cc.Invoke(ctx, UserServer_Save_FullMethodName, in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserServerServer is the server API for UserServer service.
|
||||||
|
// All implementations must embed UnimplementedUserServerServer
|
||||||
|
// for forward compatibility
|
||||||
|
type UserServerServer interface {
|
||||||
|
Save(context.Context, *SaveReq) (*SaveRsp, error)
|
||||||
|
mustEmbedUnimplementedUserServerServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedUserServerServer must be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedUserServerServer struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedUserServerServer) Save(context.Context, *SaveReq) (*SaveRsp, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method Save not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedUserServerServer) mustEmbedUnimplementedUserServerServer() {}
|
||||||
|
|
||||||
|
// UnsafeUserServerServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to UserServerServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeUserServerServer interface {
|
||||||
|
mustEmbedUnimplementedUserServerServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterUserServerServer(s grpc.ServiceRegistrar, srv UserServerServer) {
|
||||||
|
s.RegisterService(&UserServer_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _UserServer_Save_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SaveReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(UserServerServer).Save(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: UserServer_Save_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(UserServerServer).Save(ctx, req.(*SaveReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserServer_ServiceDesc is the grpc.ServiceDesc for UserServer service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var UserServer_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "user.UserServer",
|
||||||
|
HandlerType: (*UserServerServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "Save",
|
||||||
|
Handler: _UserServer_Save_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "user.proto",
|
||||||
|
}
|
|
@ -1,21 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"mongo.games.com/game/db/model"
|
|
||||||
"mongo.games.com/game/db/proto/lottery"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
grpc 服务端注册
|
|
||||||
*/
|
|
||||||
|
|
||||||
// registerGrpcServer 注册grpc服务
|
|
||||||
func registerGrpcServer() {
|
|
||||||
lottery.RegisterLotteryServerServer(GrpcServer, new(model.LotteryServer))
|
|
||||||
}
|
|
||||||
|
|
||||||
var LotteryClient lottery.LotteryServerClient
|
|
||||||
|
|
||||||
func registerGrpcClient() {
|
|
||||||
LotteryClient = lottery.NewLotteryServerClient(GrpcClientConn)
|
|
||||||
}
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package rpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
|
||||||
|
"mongo.games.com/game/db/proto/user"
|
||||||
|
"mongo.games.com/game/db/rpc/server"
|
||||||
|
"mongo.games.com/game/db/rpc/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GrpcServer grpc服务
|
||||||
|
var GrpcServer *grpc.Server
|
||||||
|
|
||||||
|
// GrpcClientConn grpc客户端连接
|
||||||
|
var GrpcClientConn *grpc.ClientConn
|
||||||
|
|
||||||
|
// RunGrpcServer 启动grpc服务端
|
||||||
|
func RunGrpcServer(addr string) {
|
||||||
|
GrpcServer = grpc.NewServer()
|
||||||
|
registerGrpcServer()
|
||||||
|
ln, err := net.Listen("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
panic(errors.New("db grpc failed to listen: " + err.Error()))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = GrpcServer.Serve(ln)
|
||||||
|
if err != nil {
|
||||||
|
panic(errors.New("db grpc failed to serve: " + err.Error()))
|
||||||
|
}
|
||||||
|
logger.Logger.Infof("db grpc start success")
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGrpcClientConn 创建grpc客户端连接
|
||||||
|
func NewGrpcClientConn(addr string) {
|
||||||
|
var err error
|
||||||
|
GrpcClientConn, err = grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
|
if err != nil {
|
||||||
|
panic(errors.New("db grpc failed to dial: " + err.Error()))
|
||||||
|
}
|
||||||
|
registerGrpcClient()
|
||||||
|
}
|
||||||
|
|
||||||
|
// registerGrpcServer 注册grpc服务
|
||||||
|
func registerGrpcServer() {
|
||||||
|
ctx := svc.NewServiceContext()
|
||||||
|
user.RegisterUserServerServer(GrpcServer, server.NewUserServer(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
var UserClient user.UserServerClient
|
||||||
|
|
||||||
|
func registerGrpcClient() {
|
||||||
|
UserClient = user.NewUserServerClient(GrpcClientConn)
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"mongo.games.com/game/db/dao"
|
||||||
|
"mongo.games.com/game/db/model"
|
||||||
|
"mongo.games.com/game/db/proto/user"
|
||||||
|
"mongo.games.com/game/db/rpc/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogic {
|
||||||
|
return &UserLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UserLogic) Save(in *user.SaveReq) (*user.SaveRsp, error) {
|
||||||
|
u, err := svc.GetUserCollection(in.GetPlatform(), model.User{}, dao.NewUser)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = u.InsertOne(l.ctx, &model.User{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &user.SaveRsp{}, nil
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.7.2
|
||||||
|
// Source: user.proto
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"mongo.games.com/game/db/proto/user"
|
||||||
|
"mongo.games.com/game/db/rpc/logic"
|
||||||
|
"mongo.games.com/game/db/rpc/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserServer struct {
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
user.UnimplementedUserServerServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserServer(svcCtx *svc.ServiceContext) *UserServer {
|
||||||
|
return &UserServer{
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserServer) Save(ctx context.Context, in *user.SaveReq) (*user.SaveRsp, error) {
|
||||||
|
l := logic.NewUserLogic(ctx, s.svcCtx)
|
||||||
|
return l.Save(in)
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
|
||||||
|
"mongo.games.com/game/common"
|
||||||
|
mon "mongo.games.com/game/mongo"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ServiceContext 服务上下文
|
||||||
|
// 依赖注入
|
||||||
|
type ServiceContext struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext() *ServiceContext {
|
||||||
|
|
||||||
|
vp := common.GetViper("mgo", "json")
|
||||||
|
// mongo初始化
|
||||||
|
conf := &mon.Config{}
|
||||||
|
err := vp.Unmarshal(conf)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("mongo config error: %v", err))
|
||||||
|
}
|
||||||
|
mon.Init(conf)
|
||||||
|
|
||||||
|
return &ServiceContext{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type TableName interface {
|
||||||
|
TableName() string
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTableName 获取表名
|
||||||
|
func GetTableName(model any) string {
|
||||||
|
if m, ok := model.(TableName); ok {
|
||||||
|
return m.TableName()
|
||||||
|
}
|
||||||
|
|
||||||
|
t := reflect.TypeOf(model)
|
||||||
|
if t.Kind() == reflect.Ptr {
|
||||||
|
t = t.Elem()
|
||||||
|
}
|
||||||
|
if t.Kind() != reflect.Struct {
|
||||||
|
panic("model must be a struct or a pointer to a struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.ToLower(t.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserCollection 用户库
|
||||||
|
func GetUserCollection[T any](platform string, model any, f func(database *mongo.Database, c *mongo.Collection) T) (T, error) {
|
||||||
|
c, err := mon.GetUserCollection(platform, GetTableName(model))
|
||||||
|
if err != nil {
|
||||||
|
var z T
|
||||||
|
logger.Logger.Errorf("GetUserCollection error: %v", err)
|
||||||
|
return z, err
|
||||||
|
}
|
||||||
|
return f(c.Database.Database, c.Collection), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLogCollection 日志库
|
||||||
|
func GetLogCollection[T any](platform string, model any, f func(database *mongo.Database, c *mongo.Collection) T) (T, error) {
|
||||||
|
c, err := mon.GetLogCollection(platform, GetTableName(model))
|
||||||
|
if err != nil {
|
||||||
|
var z T
|
||||||
|
logger.Logger.Errorf("GetLogCollection error: %v", err)
|
||||||
|
return z, err
|
||||||
|
}
|
||||||
|
return f(c.Database.Database, c.Collection), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGlobalUserCollection 全局用户库
|
||||||
|
func GetGlobalUserCollection[T any](model any, f func(database *mongo.Database, c *mongo.Collection) T) (T, error) {
|
||||||
|
c, err := mon.GetGlobalUserCollection(GetTableName(model))
|
||||||
|
if err != nil {
|
||||||
|
var z T
|
||||||
|
logger.Logger.Errorf("GetGlobalUserCollection error: %v", err)
|
||||||
|
return z, err
|
||||||
|
}
|
||||||
|
return f(c.Database.Database, c.Collection), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGlobalLogCollection 全局日志库
|
||||||
|
func GetGlobalLogCollection[T any](model any, f func(database *mongo.Database, c *mongo.Collection) T) (T, error) {
|
||||||
|
c, err := mon.GetGlobalLogCollection(GetTableName(model))
|
||||||
|
if err != nil {
|
||||||
|
var z T
|
||||||
|
logger.Logger.Errorf("GetGlobalLogCollection error: %v", err)
|
||||||
|
return z, err
|
||||||
|
}
|
||||||
|
return f(c.Database.Database, c.Collection), nil
|
||||||
|
}
|
Loading…
Reference in New Issue