Compare commits
6 Commits
be7b922cbf
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ca8a0ccbb | |||
| 5a0f4b71d4 | |||
| 44ebbe4449 | |||
| 5dc5391b07 | |||
| 427fca7ed1 | |||
| a2251b9cb7 |
@@ -37,6 +37,10 @@ func GetClient() *Client {
|
|||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) Raw() *clientv3.Client {
|
||||||
|
return c.cli
|
||||||
|
}
|
||||||
|
|
||||||
// Get 获取数据
|
// Get 获取数据
|
||||||
func (c *Client) Get(key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) {
|
func (c *Client) Get(key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package kafka
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/mmorpg/service-common/log"
|
||||||
@@ -27,10 +28,16 @@ type Consumer struct {
|
|||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Consumer) Consume(topic string, h Handler) {
|
func (c *Consumer) Consume(t []Topic) {
|
||||||
for {
|
for {
|
||||||
err := client.consumer.Consume(c.ctx, []string{topic}, &handler{
|
topicArr := make([]string, 0)
|
||||||
handler: h,
|
handlerMap := make(map[string]Topic)
|
||||||
|
for _, v := range t {
|
||||||
|
topicArr = append(topicArr, v.Name())
|
||||||
|
handlerMap[v.Name()] = v
|
||||||
|
}
|
||||||
|
err := client.consumer.Consume(c.ctx, topicArr, &handler{
|
||||||
|
handler: handlerMap,
|
||||||
})
|
})
|
||||||
if errors.Is(err, context.Canceled) || errors.Is(c.ctx.Err(), context.Canceled) {
|
if errors.Is(err, context.Canceled) || errors.Is(c.ctx.Err(), context.Canceled) {
|
||||||
return
|
return
|
||||||
@@ -44,11 +51,10 @@ func (c *Consumer) Stop() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Handler func(context.Context, *sarama.ConsumerMessage) error
|
type Handler func(context.Context, []byte) error
|
||||||
|
|
||||||
type handler struct {
|
type handler struct {
|
||||||
handler Handler
|
handler map[string]Topic
|
||||||
serviceName string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) Setup(_ sarama.ConsumerGroupSession) error {
|
func (h *handler) Setup(_ sarama.ConsumerGroupSession) error {
|
||||||
@@ -64,7 +70,21 @@ func (h *handler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.Co
|
|||||||
for message := range claim.Messages() {
|
for message := range claim.Messages() {
|
||||||
ctx := NewCarrier().ExtractConsumer(message.Headers)
|
ctx := NewCarrier().ExtractConsumer(message.Headers)
|
||||||
_, span := otel.Tracer("common.db.kafka").Start(ctx, "kafka.consume")
|
_, span := otel.Tracer("common.db.kafka").Start(ctx, "kafka.consume")
|
||||||
if err := h.handler(ctx, message); err != nil {
|
|
||||||
|
cb := h.handler[message.Topic]
|
||||||
|
if cb == nil {
|
||||||
|
span.SetStatus(otelcodes.Error, "handler not found")
|
||||||
|
span.End()
|
||||||
|
return utils.ErrorsWrap(errors.New("handler not found"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(message.Value, cb); err != nil {
|
||||||
|
span.SetStatus(otelcodes.Error, "handler json.Unmarshal error")
|
||||||
|
span.End()
|
||||||
|
return utils.ErrorsWrap(err, "handler json.Unmarshal error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cb.OnMessage(ctx); err != nil {
|
||||||
if stack, ok := err.(interface{ StackTrace() string }); ok {
|
if stack, ok := err.(interface{ StackTrace() string }); ok {
|
||||||
span.AddEvent("Stack Trace", trace.WithAttributes(
|
span.AddEvent("Stack Trace", trace.WithAttributes(
|
||||||
attribute.String("stack.trace", fmt.Sprintf("%v", stack.StackTrace())),
|
attribute.String("stack.trace", fmt.Sprintf("%v", stack.StackTrace())),
|
||||||
@@ -74,6 +94,7 @@ func (h *handler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.Co
|
|||||||
span.End()
|
span.End()
|
||||||
return utils.ErrorsWrap(err, "kafka handler error")
|
return utils.ErrorsWrap(err, "kafka handler error")
|
||||||
}
|
}
|
||||||
|
|
||||||
sess.MarkMessage(message, "")
|
sess.MarkMessage(message, "")
|
||||||
span.End()
|
span.End()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package kafka
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"github.com/IBM/sarama"
|
"github.com/IBM/sarama"
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
otelcodes "go.opentelemetry.io/otel/codes"
|
otelcodes "go.opentelemetry.io/otel/codes"
|
||||||
@@ -14,10 +15,11 @@ func NewProducer() *Producer {
|
|||||||
type Producer struct {
|
type Producer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Producer) Produce(ctx context.Context, topic, value string) {
|
func (c *Producer) Produce(ctx context.Context, data Topic) {
|
||||||
|
marshal, _ := json.Marshal(data)
|
||||||
msg := &sarama.ProducerMessage{
|
msg := &sarama.ProducerMessage{
|
||||||
Topic: topic,
|
Topic: data.Name(),
|
||||||
Value: sarama.StringEncoder(value),
|
Value: sarama.ByteEncoder(marshal),
|
||||||
Headers: NewCarrier().Inject(ctx),
|
Headers: NewCarrier().Inject(ctx),
|
||||||
}
|
}
|
||||||
client.producer.Input() <- msg
|
client.producer.Input() <- msg
|
||||||
|
|||||||
8
db/kafka/topic.go
Normal file
8
db/kafka/topic.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package kafka
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type Topic interface {
|
||||||
|
Name() string
|
||||||
|
OnMessage(context.Context) error
|
||||||
|
}
|
||||||
@@ -49,6 +49,10 @@ func (c *Client) Set(ctx context.Context, key string, value interface{}, expirat
|
|||||||
return c.cli.Set(ctx, key, value, expiration)
|
return c.cli.Set(ctx, key, value, expiration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd {
|
||||||
|
return c.cli.SetNX(ctx, key, value, expiration)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) Get(ctx context.Context, key string) *redis.StringCmd {
|
func (c *Client) Get(ctx context.Context, key string) *redis.StringCmd {
|
||||||
return c.cli.Get(ctx, key)
|
return c.cli.Get(ctx, key)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ var (
|
|||||||
// ServiceProvider 服务提供者
|
// ServiceProvider 服务提供者
|
||||||
type ServiceProvider struct {
|
type ServiceProvider struct {
|
||||||
Target string
|
Target string
|
||||||
SID string
|
SID int64
|
||||||
Addr string
|
Addr string
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstanceProvider 副本提供者
|
// InstanceProvider 副本提供者
|
||||||
type InstanceProvider struct {
|
type InstanceProvider struct {
|
||||||
InstanceID int // 副本ID
|
InstanceID int // 副本ID
|
||||||
UniqueNo string // 副本唯一编号
|
UniqueNo int64 // 副本唯一编号
|
||||||
SID string
|
SID int64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"git.hlsq.asia/mmorpg/service-common/db/etcd"
|
"git.hlsq.asia/mmorpg/service-common/db/etcd"
|
||||||
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/mmorpg/service-common/log"
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@@ -12,8 +13,8 @@ import (
|
|||||||
// 大量读少量写的情况下,读写锁比同步Map更高效
|
// 大量读少量写的情况下,读写锁比同步Map更高效
|
||||||
var (
|
var (
|
||||||
instanceMU = sync.RWMutex{}
|
instanceMU = sync.RWMutex{}
|
||||||
instanceM = make(map[string]string) // [uniqueNo]sid
|
instanceM = make(map[int64]int64) // [uniqueNo]sid
|
||||||
instanceLeaseM = make(map[string]clientv3.LeaseID) // [uniqueNo]
|
instanceLeaseM = make(map[int64]clientv3.LeaseID) // [uniqueNo]
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -22,7 +23,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindInstanceByUniqueNo 根据唯一标识查询副本
|
// FindInstanceByUniqueNo 根据唯一标识查询副本
|
||||||
func FindInstanceByUniqueNo(uniqueNO string) (sid string) {
|
func FindInstanceByUniqueNo(uniqueNO int64) (sid int64) {
|
||||||
instanceMU.RLock()
|
instanceMU.RLock()
|
||||||
defer instanceMU.RUnlock()
|
defer instanceMU.RUnlock()
|
||||||
if c, ok := instanceM[uniqueNO]; ok {
|
if c, ok := instanceM[uniqueNO]; ok {
|
||||||
@@ -32,7 +33,7 @@ func FindInstanceByUniqueNo(uniqueNO string) (sid string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RegisterInstance 注册副本
|
// RegisterInstance 注册副本
|
||||||
func RegisterInstance(sid string, instanceID int32, uniqueNo string, ttl int64) error {
|
func RegisterInstance(sid int64, instanceID int32, uniqueNo int64, ttl int64) error {
|
||||||
serverMU.Lock()
|
serverMU.Lock()
|
||||||
defer serverMU.Unlock()
|
defer serverMU.Unlock()
|
||||||
leaseID, err := common.NewLeaseAndKeepAlive(ttl)
|
leaseID, err := common.NewLeaseAndKeepAlive(ttl)
|
||||||
@@ -40,7 +41,7 @@ func RegisterInstance(sid string, instanceID int32, uniqueNo string, ttl int64)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
key := fmt.Sprintf("%v/%v/%v", common.KeyDiscoverInstance, instanceID, uniqueNo)
|
key := fmt.Sprintf("%v/%v/%v", common.KeyDiscoverInstance, instanceID, uniqueNo)
|
||||||
_, err = etcd.GetClient().Put(key, sid, clientv3.WithLease(leaseID))
|
_, err = etcd.GetClient().Put(key, utils.Int64ToString(sid), clientv3.WithLease(leaseID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -49,7 +50,7 @@ func RegisterInstance(sid string, instanceID int32, uniqueNo string, ttl int64)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnRegisterInstance 解注册副本
|
// UnRegisterInstance 解注册副本
|
||||||
func UnRegisterInstance(uniqueNo string) {
|
func UnRegisterInstance(uniqueNo int64) {
|
||||||
serverMU.Lock()
|
serverMU.Lock()
|
||||||
defer serverMU.Unlock()
|
defer serverMU.Unlock()
|
||||||
if leaseID, ok := instanceLeaseM[uniqueNo]; ok {
|
if leaseID, ok := instanceLeaseM[uniqueNo]; ok {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"git.hlsq.asia/mmorpg/service-common/db/etcd"
|
"git.hlsq.asia/mmorpg/service-common/db/etcd"
|
||||||
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/mmorpg/service-common/log"
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||||
"go.etcd.io/etcd/api/v3/mvccpb"
|
"go.etcd.io/etcd/api/v3/mvccpb"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -89,13 +90,13 @@ func onServerChange(t mvccpb.Event_EventType, key, value string) {
|
|||||||
case clientv3.EventTypePut:
|
case clientv3.EventTypePut:
|
||||||
onCBByType(common.ListenerTypeNewServer, &common.ServiceProvider{
|
onCBByType(common.ListenerTypeNewServer, &common.ServiceProvider{
|
||||||
Target: common.KeyDiscoverService + "/" + split[2],
|
Target: common.KeyDiscoverService + "/" + split[2],
|
||||||
SID: split[3],
|
SID: utils.StringToInt64(split[3]),
|
||||||
Addr: value,
|
Addr: value,
|
||||||
})
|
})
|
||||||
case clientv3.EventTypeDelete:
|
case clientv3.EventTypeDelete:
|
||||||
onCBByType(common.ListenerTypeCloseServer, &common.ServiceProvider{
|
onCBByType(common.ListenerTypeCloseServer, &common.ServiceProvider{
|
||||||
Target: common.KeyDiscoverService + "/" + split[2],
|
Target: common.KeyDiscoverService + "/" + split[2],
|
||||||
SID: split[3],
|
SID: utils.StringToInt64(split[3]),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,14 +112,14 @@ func onInstanceChange(t mvccpb.Event_EventType, key, value string, preKv *mvccpb
|
|||||||
case clientv3.EventTypePut:
|
case clientv3.EventTypePut:
|
||||||
onCBByType(common.ListenerTypeNewInstance, &common.InstanceProvider{
|
onCBByType(common.ListenerTypeNewInstance, &common.InstanceProvider{
|
||||||
InstanceID: instanceID,
|
InstanceID: instanceID,
|
||||||
UniqueNo: split[3],
|
UniqueNo: utils.StringToInt64(split[3]),
|
||||||
SID: value,
|
SID: utils.StringToInt64(value),
|
||||||
})
|
})
|
||||||
case clientv3.EventTypeDelete:
|
case clientv3.EventTypeDelete:
|
||||||
onCBByType(common.ListenerTypeCloseInstance, &common.InstanceProvider{
|
onCBByType(common.ListenerTypeCloseInstance, &common.InstanceProvider{
|
||||||
InstanceID: instanceID,
|
InstanceID: instanceID,
|
||||||
UniqueNo: split[3],
|
UniqueNo: utils.StringToInt64(split[3]),
|
||||||
SID: string(preKv.Value),
|
SID: utils.StringToInt64(string(preKv.Value)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
serverMU = sync.RWMutex{}
|
serverMU = sync.RWMutex{}
|
||||||
conn = make(map[string]*grpc_conn.GrpcConnectionMgr)
|
conn = make(map[string]*grpc_conn.GrpcConnectionMgr)
|
||||||
serverLeaseM = make(map[string]clientv3.LeaseID)
|
serverLeaseM = make(map[int64]clientv3.LeaseID)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -24,7 +24,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindServer 根据SID或随机查找服务
|
// FindServer 根据SID或随机查找服务
|
||||||
func FindServer(target string, sid ...string) (*grpc.ClientConn, error) {
|
func FindServer(target string, sid ...int64) (*grpc.ClientConn, error) {
|
||||||
serverMU.RLock()
|
serverMU.RLock()
|
||||||
defer serverMU.RUnlock()
|
defer serverMU.RUnlock()
|
||||||
if v, ok := conn[target]; ok {
|
if v, ok := conn[target]; ok {
|
||||||
@@ -33,17 +33,17 @@ func FindServer(target string, sid ...string) (*grpc.ClientConn, error) {
|
|||||||
return nil, fmt.Errorf("cannot find server")
|
return nil, fmt.Errorf("cannot find server")
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindServerAll(target string) map[string]*grpc.ClientConn {
|
func FindServerAll(target string) map[int64]*grpc.ClientConn {
|
||||||
serverMU.RLock()
|
serverMU.RLock()
|
||||||
defer serverMU.RUnlock()
|
defer serverMU.RUnlock()
|
||||||
if v, ok := conn[target]; ok {
|
if v, ok := conn[target]; ok {
|
||||||
return v.LoadAll()
|
return v.LoadAll()
|
||||||
}
|
}
|
||||||
return make(map[string]*grpc.ClientConn)
|
return make(map[int64]*grpc.ClientConn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterGrpcServer 注册服务提供者
|
// RegisterGrpcServer 注册服务提供者
|
||||||
func RegisterGrpcServer(target string, sid string, addr string, ttl int64) error {
|
func RegisterGrpcServer(target string, sid int64, addr string, ttl int64) error {
|
||||||
serverMU.Lock()
|
serverMU.Lock()
|
||||||
defer serverMU.Unlock()
|
defer serverMU.Unlock()
|
||||||
leaseID, err := common.NewLeaseAndKeepAlive(ttl)
|
leaseID, err := common.NewLeaseAndKeepAlive(ttl)
|
||||||
@@ -59,7 +59,7 @@ func RegisterGrpcServer(target string, sid string, addr string, ttl int64) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnRegisterGrpcServer 解注册服务提供者
|
// UnRegisterGrpcServer 解注册服务提供者
|
||||||
func UnRegisterGrpcServer(sid string) {
|
func UnRegisterGrpcServer(sid int64) {
|
||||||
serverMU.Lock()
|
serverMU.Lock()
|
||||||
defer serverMU.Unlock()
|
defer serverMU.Unlock()
|
||||||
if leaseID, ok := serverLeaseM[sid]; ok {
|
if leaseID, ok := serverLeaseM[sid]; ok {
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/config"
|
||||||
"github.com/natefinch/lumberjack"
|
"github.com/natefinch/lumberjack"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init(debug bool, maxSize, maxBackups, maxAge int32, level string) {
|
func Init(cfg *config.LogConfig) {
|
||||||
// 格式配置
|
// 格式配置
|
||||||
jsonConfig := zapcore.EncoderConfig{
|
jsonConfig := zapcore.EncoderConfig{
|
||||||
MessageKey: "M",
|
MessageKey: "M",
|
||||||
@@ -30,19 +31,19 @@ func Init(debug bool, maxSize, maxBackups, maxAge int32, level string) {
|
|||||||
|
|
||||||
// 日志输出到控制台和文件
|
// 日志输出到控制台和文件
|
||||||
writeSyncer := []zapcore.WriteSyncer{zapcore.AddSync(os.Stdout)}
|
writeSyncer := []zapcore.WriteSyncer{zapcore.AddSync(os.Stdout)}
|
||||||
if !debug {
|
if !cfg.Debug {
|
||||||
writeSyncer = append(writeSyncer, zapcore.AddSync(&lumberjack.Logger{
|
writeSyncer = append(writeSyncer, zapcore.AddSync(&lumberjack.Logger{
|
||||||
Filename: "./logs/log.log", // 日志文件位置
|
Filename: "./logs/log.log", // 日志文件位置
|
||||||
MaxSize: int(maxSize), // 最大文件大小(MB)
|
MaxSize: int(cfg.MaxSize), // 最大文件大小(MB)
|
||||||
MaxBackups: int(maxBackups), // 保留旧文件的最大个数
|
MaxBackups: int(cfg.MaxBackups), // 保留旧文件的最大个数
|
||||||
MaxAge: int(maxAge), // 保留旧文件的最大天数
|
MaxAge: int(cfg.MaxAge), // 保留旧文件的最大天数
|
||||||
Compress: false, // 是否压缩/归档旧文件
|
Compress: false, // 是否压缩/归档旧文件
|
||||||
LocalTime: true,
|
LocalTime: true,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
var encoder zapcore.Encoder
|
var encoder zapcore.Encoder
|
||||||
if debug {
|
if cfg.Debug {
|
||||||
encoder = zapcore.NewConsoleEncoder(jsonConfig)
|
encoder = zapcore.NewConsoleEncoder(jsonConfig)
|
||||||
} else {
|
} else {
|
||||||
encoder = zapcore.NewJSONEncoder(jsonConfig)
|
encoder = zapcore.NewJSONEncoder(jsonConfig)
|
||||||
@@ -50,9 +51,9 @@ func Init(debug bool, maxSize, maxBackups, maxAge int32, level string) {
|
|||||||
logger := zap.New(zapcore.NewCore(
|
logger := zap.New(zapcore.NewCore(
|
||||||
encoder,
|
encoder,
|
||||||
zapcore.NewMultiWriteSyncer(writeSyncer...),
|
zapcore.NewMultiWriteSyncer(writeSyncer...),
|
||||||
zap.NewAtomicLevelAt(GetLogLevel(level)),
|
zap.NewAtomicLevelAt(GetLogLevel(cfg.Level)),
|
||||||
))
|
))
|
||||||
if debug {
|
if cfg.Debug {
|
||||||
logger = logger.WithOptions(
|
logger = logger.WithOptions(
|
||||||
zap.AddCaller(),
|
zap.AddCaller(),
|
||||||
zap.AddCallerSkip(1),
|
zap.AddCallerSkip(1),
|
||||||
|
|||||||
33
module/db.go
33
module/db.go
@@ -12,32 +12,32 @@ import (
|
|||||||
// DB 数据库模块
|
// DB 数据库模块
|
||||||
type DB struct {
|
type DB struct {
|
||||||
DefaultModule
|
DefaultModule
|
||||||
cfg *config.DBConfig
|
Cfg *config.DBConfig
|
||||||
appName string
|
AppName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DB) Init() error {
|
func (m *DB) Init() error {
|
||||||
// ETCD
|
// ETCD
|
||||||
if m.cfg.Etcd != nil {
|
if m.Cfg.Etcd != nil {
|
||||||
if err := etcd.Init(m.cfg.Etcd); err != nil {
|
if err := etcd.Init(m.Cfg.Etcd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// MYSQL
|
// MYSQL
|
||||||
if m.cfg.MySQL != nil {
|
if m.Cfg.MySQL != nil {
|
||||||
if err := mysql.Init(m.cfg.MySQL); err != nil {
|
if err := mysql.Init(m.Cfg.MySQL); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// REDIS
|
// REDIS
|
||||||
if m.cfg.Redis != nil {
|
if m.Cfg.Redis != nil {
|
||||||
if err := redis.Init(m.cfg.Redis); err != nil {
|
if err := redis.Init(m.Cfg.Redis); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// KAFKA
|
// KAFKA
|
||||||
if m.cfg.Kafka != nil {
|
if m.Cfg.Kafka != nil {
|
||||||
if err := kafka.Init(m.cfg.Kafka, m.appName); err != nil {
|
if err := kafka.Init(m.Cfg.Kafka, m.AppName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,16 +59,3 @@ func (m *DB) Stop() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DB) Bind(data ...any) Module {
|
|
||||||
if data == nil || len(data) == 0 {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
if cfg, ok := data[0].(*config.DBConfig); ok {
|
|
||||||
m.cfg = cfg
|
|
||||||
}
|
|
||||||
if appName, ok := data[1].(string); ok {
|
|
||||||
m.appName = appName
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,30 +8,20 @@ import (
|
|||||||
// Grpc Grpc模块
|
// Grpc Grpc模块
|
||||||
type Grpc struct {
|
type Grpc struct {
|
||||||
DefaultModule
|
DefaultModule
|
||||||
server service.IService
|
Server service.IService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Grpc) Start(ready *sync.WaitGroup) error {
|
func (m *Grpc) Start(ready *sync.WaitGroup) error {
|
||||||
m.server.Init(ready)
|
m.Server.Init(ready)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Grpc) AfterStart() error {
|
func (m *Grpc) AfterStart() error {
|
||||||
m.server.SetReady()
|
m.Server.SetReady()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Grpc) Stop() error {
|
func (m *Grpc) Stop() error {
|
||||||
m.server.Close()
|
m.Server.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Grpc) Bind(data ...any) Module {
|
|
||||||
if data == nil || len(data) == 0 {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
if ser, ok := data[0].(service.IService); ok {
|
|
||||||
m.server = ser
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|||||||
17
module/log.go
Normal file
17
module/log.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package module
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/config"
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Log 日志模块
|
||||||
|
type Log struct {
|
||||||
|
DefaultModule
|
||||||
|
Cfg *config.LogConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Log) Init() error {
|
||||||
|
log.Init(m.Cfg)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ type Module interface {
|
|||||||
Start(ready *sync.WaitGroup) error // 启动
|
Start(ready *sync.WaitGroup) error // 启动
|
||||||
AfterStart() error // 启动之后
|
AfterStart() error // 启动之后
|
||||||
Stop() error // 停止
|
Stop() error // 停止
|
||||||
Bind(data ...any) Module // 绑定数据
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DefaultModule struct {
|
type DefaultModule struct {
|
||||||
@@ -31,7 +30,3 @@ func (m *DefaultModule) AfterStart() error {
|
|||||||
func (m *DefaultModule) Stop() error {
|
func (m *DefaultModule) Stop() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DefaultModule) Bind(_ ...any) Module {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ import (
|
|||||||
// Prometheus 普罗米修斯模块
|
// Prometheus 普罗米修斯模块
|
||||||
type Prometheus struct {
|
type Prometheus struct {
|
||||||
DefaultModule
|
DefaultModule
|
||||||
|
Cfg *config.MetricConfig
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
server *http.Server
|
server *http.Server
|
||||||
metricCfg *config.MetricConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Prometheus) Init() error {
|
func (m *Prometheus) Init() error {
|
||||||
@@ -29,7 +29,7 @@ func (m *Prometheus) Start(ready *sync.WaitGroup) error {
|
|||||||
go func() {
|
go func() {
|
||||||
defer m.wg.Done()
|
defer m.wg.Done()
|
||||||
m.server = &http.Server{
|
m.server = &http.Server{
|
||||||
Addr: fmt.Sprintf("%v:%v", m.metricCfg.Prometheus.Address, m.metricCfg.Prometheus.Port),
|
Addr: fmt.Sprintf("%v:%v", m.Cfg.Prometheus.Address, m.Cfg.Prometheus.Port),
|
||||||
Handler: promhttp.Handler(),
|
Handler: promhttp.Handler(),
|
||||||
}
|
}
|
||||||
ready.Done()
|
ready.Done()
|
||||||
@@ -48,13 +48,3 @@ func (m *Prometheus) Stop() error {
|
|||||||
m.wg.Wait()
|
m.wg.Wait()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Prometheus) Bind(data ...any) Module {
|
|
||||||
if data == nil || len(data) == 0 {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
if mc, ok := data[0].(*config.MetricConfig); ok {
|
|
||||||
m.metricCfg = mc
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|||||||
64
module/snowflake.go
Normal file
64
module/snowflake.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package module
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/db/etcd"
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||||
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
|
"go.etcd.io/etcd/client/v3/concurrency"
|
||||||
|
"math/rand"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Snowflake 雪花模块
|
||||||
|
type Snowflake struct {
|
||||||
|
DefaultModule
|
||||||
|
snowflakeSession *concurrency.Session
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Snowflake) Init() error {
|
||||||
|
node, session, err := acquire(context.Background(), 1, 1000)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
m.snowflakeSession = session
|
||||||
|
utils.InitSnowflake(node)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Snowflake) Stop() error {
|
||||||
|
_ = m.snowflakeSession.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func acquire(ctx context.Context, min, max int) (int64, *concurrency.Session, error) {
|
||||||
|
nums := rand.Perm(max - min + 1)
|
||||||
|
for i := range nums {
|
||||||
|
nums[i] += min
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, n := range nums {
|
||||||
|
key := fmt.Sprintf("node/num/%d", n)
|
||||||
|
|
||||||
|
session, err := concurrency.NewSession(
|
||||||
|
etcd.GetClient().Raw(),
|
||||||
|
concurrency.WithContext(ctx),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, utils.ErrorsWrap(fmt.Errorf("etcd NewSession error: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
txnResp, _ := etcd.GetClient().Raw().Txn(ctx).
|
||||||
|
If(clientv3.Compare(clientv3.CreateRevision(key), "=", 0)).
|
||||||
|
Then(clientv3.OpPut(key, "", clientv3.WithLease(session.Lease()))).
|
||||||
|
Commit()
|
||||||
|
|
||||||
|
if txnResp.Succeeded {
|
||||||
|
return int64(n), session, nil
|
||||||
|
} else {
|
||||||
|
_ = session.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, nil, utils.ErrorsWrap(errors.New("etcd num empty"), "acquire error")
|
||||||
|
}
|
||||||
@@ -15,16 +15,16 @@ import (
|
|||||||
// Tracer 链路追踪模块
|
// Tracer 链路追踪模块
|
||||||
type Tracer struct {
|
type Tracer struct {
|
||||||
DefaultModule
|
DefaultModule
|
||||||
|
Cfg *config.MetricConfig
|
||||||
|
ServiceName string
|
||||||
tp *sdktrace.TracerProvider
|
tp *sdktrace.TracerProvider
|
||||||
metricCfg *config.MetricConfig
|
|
||||||
serviceName string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Tracer) Init() error {
|
func (m *Tracer) Init() error {
|
||||||
exporter, err := otlptracegrpc.New(
|
exporter, err := otlptracegrpc.New(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
otlptracegrpc.WithInsecure(),
|
otlptracegrpc.WithInsecure(),
|
||||||
otlptracegrpc.WithEndpoint(m.metricCfg.Jaeger.Endpoint),
|
otlptracegrpc.WithEndpoint(m.Cfg.Jaeger.Endpoint),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -34,7 +34,7 @@ func (m *Tracer) Init() error {
|
|||||||
sdktrace.WithBatcher(exporter),
|
sdktrace.WithBatcher(exporter),
|
||||||
sdktrace.WithResource(resource.NewWithAttributes(
|
sdktrace.WithResource(resource.NewWithAttributes(
|
||||||
semconv.SchemaURL,
|
semconv.SchemaURL,
|
||||||
semconv.ServiceNameKey.String(m.serviceName),
|
semconv.ServiceNameKey.String(m.ServiceName),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
otel.SetTracerProvider(m.tp)
|
otel.SetTracerProvider(m.tp)
|
||||||
@@ -51,16 +51,3 @@ func (m *Tracer) Stop() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Tracer) Bind(data ...any) Module {
|
|
||||||
if data == nil || len(data) == 0 {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
if mc, ok := data[0].(*config.MetricConfig); ok {
|
|
||||||
m.metricCfg = mc
|
|
||||||
}
|
|
||||||
if name, ok := data[1].(string); ok {
|
|
||||||
m.serviceName = name
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GatewayNewClient(sid ...string) (grpc_pb.GatewayClient, error) {
|
func GatewayNewClient(sid ...int64) (grpc_pb.GatewayClient, error) {
|
||||||
c, err := discover.FindServer(common.KeyDiscoverGateway, sid...)
|
c, err := discover.FindServer(common.KeyDiscoverGateway, sid...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -14,8 +14,8 @@ func GatewayNewClient(sid ...string) (grpc_pb.GatewayClient, error) {
|
|||||||
return grpc_pb.NewGatewayClient(c), nil
|
return grpc_pb.NewGatewayClient(c), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GatewayNewBroadcastClient() map[string]grpc_pb.GatewayClient {
|
func GatewayNewBroadcastClient() map[int64]grpc_pb.GatewayClient {
|
||||||
clientM := make(map[string]grpc_pb.GatewayClient)
|
clientM := make(map[int64]grpc_pb.GatewayClient)
|
||||||
connM := discover.FindServerAll(common.KeyDiscoverGateway)
|
connM := discover.FindServerAll(common.KeyDiscoverGateway)
|
||||||
for sid, conn := range connM {
|
for sid, conn := range connM {
|
||||||
clientM[sid] = grpc_pb.NewGatewayClient(conn)
|
clientM[sid] = grpc_pb.NewGatewayClient(conn)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func QgdzsNewClient(sid ...string) (grpc_pb.QgdzsClient, error) {
|
func QgdzsNewClient(sid ...int64) (grpc_pb.QgdzsClient, error) {
|
||||||
c, err := discover.FindServer(common.KeyDiscoverQgdzs, sid...)
|
c, err := discover.FindServer(common.KeyDiscoverQgdzs, sid...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SceneNewClient(sid ...string) (grpc_pb.SceneClient, error) {
|
func SceneNewClient(sid ...int64) (grpc_pb.SceneClient, error) {
|
||||||
c, err := discover.FindServer(common.KeyDiscoverScene, sid...)
|
c, err := discover.FindServer(common.KeyDiscoverScene, sid...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -23,8 +23,8 @@ func SceneNewClientLB() (grpc_pb.SceneClient, error) {
|
|||||||
return grpc_pb.NewSceneClient(c), nil
|
return grpc_pb.NewSceneClient(c), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SceneNewBroadcastClient() map[string]grpc_pb.SceneClient {
|
func SceneNewBroadcastClient() map[int64]grpc_pb.SceneClient {
|
||||||
clientM := make(map[string]grpc_pb.SceneClient)
|
clientM := make(map[int64]grpc_pb.SceneClient)
|
||||||
connM := discover.FindServerAll(common.KeyDiscoverScene)
|
connM := discover.FindServerAll(common.KeyDiscoverScene)
|
||||||
for sid, conn := range connM {
|
for sid, conn := range connM {
|
||||||
clientM[sid] = grpc_pb.NewSceneClient(conn)
|
clientM[sid] = grpc_pb.NewSceneClient(conn)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserNewClient(sid ...string) (grpc_pb.UserClient, error) {
|
func UserNewClient(sid ...int64) (grpc_pb.UserClient, error) {
|
||||||
c, err := discover.FindServer(common.KeyDiscoverUser, sid...)
|
c, err := discover.FindServer(common.KeyDiscoverUser, sid...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package grpc_client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/mmorpg/service-common/log"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ type gatewayStream struct {
|
|||||||
stream grpc.ClientStream
|
stream grpc.ClientStream
|
||||||
}
|
}
|
||||||
|
|
||||||
func findGatewayBySID(sid string, fun GatewayFun) (*gatewayStream, error) {
|
func findGatewayBySID(sid int64, fun GatewayFun) (*gatewayStream, error) {
|
||||||
key := gatewayKey(sid, fun)
|
key := gatewayKey(sid, fun)
|
||||||
|
|
||||||
if v, ok := gatewayServer.Load(key); ok {
|
if v, ok := gatewayServer.Load(key); ok {
|
||||||
@@ -53,7 +53,7 @@ func findGatewayBySID(sid string, fun GatewayFun) (*gatewayStream, error) {
|
|||||||
return ss, nil
|
return ss, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendMessageToGateway(sid string, fun GatewayFun, msg proto.Message, re ...bool) error {
|
func SendMessageToGateway(sid int64, fun GatewayFun, msg proto.Message, re ...bool) error {
|
||||||
ss, err := findGatewayBySID(sid, fun)
|
ss, err := findGatewayBySID(sid, fun)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -78,6 +78,6 @@ func SendMessageToGateway(sid string, fun GatewayFun, msg proto.Message, re ...b
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func gatewayKey(sid string, fun GatewayFun) string {
|
func gatewayKey(sid int64, fun GatewayFun) string {
|
||||||
return sid + "-" + strconv.Itoa(int(fun))
|
return fmt.Sprintf("%v-%v", sid, fun)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package grpc_client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/mmorpg/service-common/log"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ type sceneStream struct {
|
|||||||
stream grpc.ClientStream
|
stream grpc.ClientStream
|
||||||
}
|
}
|
||||||
|
|
||||||
func findSceneBySID(sid string, fun SceneFun) (*sceneStream, error) {
|
func findSceneBySID(sid int64, fun SceneFun) (*sceneStream, error) {
|
||||||
key := sceneKey(sid, fun)
|
key := sceneKey(sid, fun)
|
||||||
|
|
||||||
if v, ok := sceneServer.Load(key); ok {
|
if v, ok := sceneServer.Load(key); ok {
|
||||||
@@ -53,7 +53,7 @@ func findSceneBySID(sid string, fun SceneFun) (*sceneStream, error) {
|
|||||||
return ss, nil
|
return ss, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendMessageToScene(sid string, fun SceneFun, msg proto.Message, re ...bool) error {
|
func SendMessageToScene(sid int64, fun SceneFun, msg proto.Message, re ...bool) error {
|
||||||
ss, err := findSceneBySID(sid, fun)
|
ss, err := findSceneBySID(sid, fun)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -78,6 +78,6 @@ func SendMessageToScene(sid string, fun SceneFun, msg proto.Message, re ...bool)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sceneKey(sid string, fun SceneFun) string {
|
func sceneKey(sid int64, fun SceneFun) string {
|
||||||
return sid + "-" + strconv.Itoa(int(fun))
|
return fmt.Sprintf("%v-%v", sid, fun)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GrpcConnection struct {
|
type GrpcConnection struct {
|
||||||
sid string
|
sid int64
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGrpcConnection(sid string, address string) (*GrpcConnection, error) {
|
func NewGrpcConnection(sid int64, address string) (*GrpcConnection, error) {
|
||||||
p := &GrpcConnection{
|
p := &GrpcConnection{
|
||||||
sid: sid,
|
sid: sid,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GrpcConnectionMgr struct {
|
type GrpcConnectionMgr struct {
|
||||||
poolM map[string]*GrpcConnection
|
poolM map[int64]*GrpcConnection
|
||||||
poolS []*GrpcConnection
|
poolS []*GrpcConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGrpcConnectionMgr() *GrpcConnectionMgr {
|
func NewGrpcConnectionMgr() *GrpcConnectionMgr {
|
||||||
return &GrpcConnectionMgr{
|
return &GrpcConnectionMgr{
|
||||||
poolM: make(map[string]*GrpcConnection),
|
poolM: make(map[int64]*GrpcConnection),
|
||||||
poolS: make([]*GrpcConnection, 0),
|
poolS: make([]*GrpcConnection, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *GrpcConnectionMgr) Store(sid string, addr string) {
|
func (p *GrpcConnectionMgr) Store(sid int64, addr string) {
|
||||||
pool, err := NewGrpcConnection(sid, addr)
|
pool, err := NewGrpcConnection(sid, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("create grpc err: %v, sid: %v, addr: %v", err, sid, addr)
|
log.Errorf("create grpc err: %v, sid: %v, addr: %v", err, sid, addr)
|
||||||
@@ -29,7 +29,7 @@ func (p *GrpcConnectionMgr) Store(sid string, addr string) {
|
|||||||
p.poolS = append(p.poolS, pool)
|
p.poolS = append(p.poolS, pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *GrpcConnectionMgr) Delete(sid string) int {
|
func (p *GrpcConnectionMgr) Delete(sid int64) int {
|
||||||
delete(p.poolM, sid)
|
delete(p.poolM, sid)
|
||||||
for i, pool := range p.poolS {
|
for i, pool := range p.poolS {
|
||||||
if pool.sid == sid {
|
if pool.sid == sid {
|
||||||
@@ -40,9 +40,9 @@ func (p *GrpcConnectionMgr) Delete(sid string) int {
|
|||||||
return len(p.poolS)
|
return len(p.poolS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *GrpcConnectionMgr) Load(sid ...string) (*grpc.ClientConn, error) {
|
func (p *GrpcConnectionMgr) Load(sid ...int64) (*grpc.ClientConn, error) {
|
||||||
var pool *GrpcConnection
|
var pool *GrpcConnection
|
||||||
if len(sid) > 0 && sid[0] != "" {
|
if len(sid) > 0 && sid[0] != 0 {
|
||||||
pool = p.poolM[sid[0]]
|
pool = p.poolM[sid[0]]
|
||||||
} else {
|
} else {
|
||||||
pool = p.poolS[rand.Intn(len(p.poolS))]
|
pool = p.poolS[rand.Intn(len(p.poolS))]
|
||||||
@@ -53,8 +53,8 @@ func (p *GrpcConnectionMgr) Load(sid ...string) (*grpc.ClientConn, error) {
|
|||||||
return pool.GetConnection(), nil
|
return pool.GetConnection(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *GrpcConnectionMgr) LoadAll() map[string]*grpc.ClientConn {
|
func (p *GrpcConnectionMgr) LoadAll() map[int64]*grpc.ClientConn {
|
||||||
sidM := make(map[string]*grpc.ClientConn)
|
sidM := make(map[int64]*grpc.ClientConn)
|
||||||
for sid, pool := range p.poolM {
|
for sid, pool := range p.poolM {
|
||||||
sidM[sid] = pool.GetConnection()
|
sidM[sid] = pool.GetConnection()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type IService interface {
|
|||||||
type Base struct {
|
type Base struct {
|
||||||
Target string
|
Target string
|
||||||
ServiceName string
|
ServiceName string
|
||||||
SID string
|
SID int64
|
||||||
Serve *grpc.Server
|
Serve *grpc.Server
|
||||||
Cfg *config.GrpcConfig
|
Cfg *config.GrpcConfig
|
||||||
OnCustomGrpcServerOption func() []grpc.ServerOption
|
OnCustomGrpcServerOption func() []grpc.ServerOption
|
||||||
@@ -39,7 +39,7 @@ type Base struct {
|
|||||||
func (s *Base) Init(ready *sync.WaitGroup) {
|
func (s *Base) Init(ready *sync.WaitGroup) {
|
||||||
s.wg = &sync.WaitGroup{}
|
s.wg = &sync.WaitGroup{}
|
||||||
s.wg.Add(1)
|
s.wg.Add(1)
|
||||||
s.SID = utils.SnowflakeInstance().Generate().String()
|
s.SID = utils.SnowflakeInstance().Generate().Int64()
|
||||||
go func() {
|
go func() {
|
||||||
defer s.wg.Done()
|
defer s.wg.Done()
|
||||||
defer s.OnClose()
|
defer s.OnClose()
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type ToClientReq struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,proto3" json:"USN,omitempty"`
|
USN int64 `protobuf:"varint,1,opt,name=USN,proto3" json:"USN,omitempty"`
|
||||||
MessageID int32 `protobuf:"varint,2,opt,name=MessageID,proto3" json:"MessageID,omitempty"`
|
MessageID int32 `protobuf:"varint,2,opt,name=MessageID,proto3" json:"MessageID,omitempty"`
|
||||||
Payload []byte `protobuf:"bytes,3,opt,name=Payload,proto3" json:"Payload,omitempty"`
|
Payload []byte `protobuf:"bytes,3,opt,name=Payload,proto3" json:"Payload,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -63,11 +63,11 @@ func (*ToClientReq) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_gateway_proto_rawDescGZIP(), []int{0}
|
return file_service_gateway_proto_rawDescGZIP(), []int{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ToClientReq) GetUSN() string {
|
func (x *ToClientReq) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ToClientReq) GetMessageID() int32 {
|
func (x *ToClientReq) GetMessageID() int32 {
|
||||||
@@ -127,7 +127,7 @@ type KickUserReq struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,proto3" json:"USN,omitempty"`
|
USN int64 `protobuf:"varint,1,opt,name=USN,proto3" json:"USN,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *KickUserReq) Reset() {
|
func (x *KickUserReq) Reset() {
|
||||||
@@ -162,11 +162,11 @@ func (*KickUserReq) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_gateway_proto_rawDescGZIP(), []int{2}
|
return file_service_gateway_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *KickUserReq) GetUSN() string {
|
func (x *KickUserReq) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type KickUserResp struct {
|
type KickUserResp struct {
|
||||||
@@ -214,13 +214,13 @@ var file_service_gateway_proto_rawDesc = []byte{
|
|||||||
0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x72, 0x73, 0x5f, 0x63, 0x6f, 0x6d, 0x6d,
|
0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x72, 0x73, 0x5f, 0x63, 0x6f, 0x6d, 0x6d,
|
||||||
0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x57, 0x0a, 0x0b, 0x54, 0x6f, 0x43, 0x6c,
|
0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x57, 0x0a, 0x0b, 0x54, 0x6f, 0x43, 0x6c,
|
||||||
0x69, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01,
|
0x69, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x55, 0x53, 0x4e, 0x12, 0x1c, 0x0a, 0x09, 0x4d, 0x65, 0x73,
|
0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x55, 0x53, 0x4e, 0x12, 0x1c, 0x0a, 0x09, 0x4d, 0x65, 0x73,
|
||||||
0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x4d, 0x65,
|
0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x4d, 0x65,
|
||||||
0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f,
|
0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f,
|
||||||
0x61, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61,
|
0x61, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61,
|
||||||
0x64, 0x22, 0x0e, 0x0a, 0x0c, 0x54, 0x6f, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73,
|
0x64, 0x22, 0x0e, 0x0a, 0x0c, 0x54, 0x6f, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73,
|
||||||
0x70, 0x22, 0x1f, 0x0a, 0x0b, 0x4b, 0x69, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71,
|
0x70, 0x22, 0x1f, 0x0a, 0x0b, 0x4b, 0x69, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71,
|
||||||
0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x55,
|
0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x55,
|
||||||
0x53, 0x4e, 0x22, 0x0e, 0x0a, 0x0c, 0x4b, 0x69, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65,
|
0x53, 0x4e, 0x22, 0x0e, 0x0a, 0x0c, 0x4b, 0x69, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65,
|
||||||
0x73, 0x70, 0x32, 0x61, 0x0a, 0x07, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x2b, 0x0a,
|
0x73, 0x70, 0x32, 0x61, 0x0a, 0x07, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x2b, 0x0a,
|
||||||
0x08, 0x54, 0x6f, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x0c, 0x2e, 0x54, 0x6f, 0x43, 0x6c,
|
0x08, 0x54, 0x6f, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x0c, 0x2e, 0x54, 0x6f, 0x43, 0x6c,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -275,6 +275,54 @@ func local_request_Qgdzs_GetQuestionInfo_0(ctx context.Context, marshaler runtim
|
|||||||
return msg, metadata, err
|
return msg, metadata, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func request_Qgdzs_GetPointRecord_0(ctx context.Context, marshaler runtime.Marshaler, client QgdzsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var (
|
||||||
|
protoReq GetPointRecordReq
|
||||||
|
metadata runtime.ServerMetadata
|
||||||
|
)
|
||||||
|
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
msg, err := client.GetPointRecord(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func local_request_Qgdzs_GetPointRecord_0(ctx context.Context, marshaler runtime.Marshaler, server QgdzsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var (
|
||||||
|
protoReq GetPointRecordReq
|
||||||
|
metadata runtime.ServerMetadata
|
||||||
|
)
|
||||||
|
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
msg, err := server.GetPointRecord(ctx, &protoReq)
|
||||||
|
return msg, metadata, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func request_Qgdzs_GetPoint_0(ctx context.Context, marshaler runtime.Marshaler, client QgdzsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var (
|
||||||
|
protoReq GetPointReq
|
||||||
|
metadata runtime.ServerMetadata
|
||||||
|
)
|
||||||
|
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
msg, err := client.GetPoint(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func local_request_Qgdzs_GetPoint_0(ctx context.Context, marshaler runtime.Marshaler, server QgdzsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var (
|
||||||
|
protoReq GetPointReq
|
||||||
|
metadata runtime.ServerMetadata
|
||||||
|
)
|
||||||
|
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
msg, err := server.GetPoint(ctx, &protoReq)
|
||||||
|
return msg, metadata, err
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterQgdzsHandlerServer registers the http handlers for service Qgdzs to "mux".
|
// RegisterQgdzsHandlerServer registers the http handlers for service Qgdzs to "mux".
|
||||||
// UnaryRPC :call QgdzsServer directly.
|
// UnaryRPC :call QgdzsServer directly.
|
||||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||||
@@ -481,6 +529,46 @@ func RegisterQgdzsHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
|
|||||||
}
|
}
|
||||||
forward_Qgdzs_GetQuestionInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
forward_Qgdzs_GetQuestionInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
})
|
})
|
||||||
|
mux.Handle(http.MethodPost, pattern_Qgdzs_GetPointRecord_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
var stream runtime.ServerTransportStream
|
||||||
|
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/.Qgdzs/GetPointRecord", runtime.WithHTTPPathPattern("/qgdzs/auth/point/record"))
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := local_request_Qgdzs_GetPointRecord_0(annotatedContext, inboundMarshaler, server, req, pathParams)
|
||||||
|
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||||
|
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
forward_Qgdzs_GetPointRecord_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
})
|
||||||
|
mux.Handle(http.MethodPost, pattern_Qgdzs_GetPoint_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
var stream runtime.ServerTransportStream
|
||||||
|
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/.Qgdzs/GetPoint", runtime.WithHTTPPathPattern("/qgdzs/auth/point/info"))
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := local_request_Qgdzs_GetPoint_0(annotatedContext, inboundMarshaler, server, req, pathParams)
|
||||||
|
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||||
|
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
forward_Qgdzs_GetPoint_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -691,6 +779,40 @@ func RegisterQgdzsHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
|
|||||||
}
|
}
|
||||||
forward_Qgdzs_GetQuestionInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
forward_Qgdzs_GetQuestionInfo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
})
|
})
|
||||||
|
mux.Handle(http.MethodPost, pattern_Qgdzs_GetPointRecord_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/.Qgdzs/GetPointRecord", runtime.WithHTTPPathPattern("/qgdzs/auth/point/record"))
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Qgdzs_GetPointRecord_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||||
|
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
forward_Qgdzs_GetPointRecord_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
})
|
||||||
|
mux.Handle(http.MethodPost, pattern_Qgdzs_GetPoint_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/.Qgdzs/GetPoint", runtime.WithHTTPPathPattern("/qgdzs/auth/point/info"))
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Qgdzs_GetPoint_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||||
|
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
forward_Qgdzs_GetPoint_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -705,6 +827,8 @@ var (
|
|||||||
pattern_Qgdzs_QuicklyAnswerQuestion_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"qgdzs", "open", "quickly", "answer"}, ""))
|
pattern_Qgdzs_QuicklyAnswerQuestion_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"qgdzs", "open", "quickly", "answer"}, ""))
|
||||||
pattern_Qgdzs_GetRecord_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"qgdzs", "auth", "get_record"}, ""))
|
pattern_Qgdzs_GetRecord_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"qgdzs", "auth", "get_record"}, ""))
|
||||||
pattern_Qgdzs_GetQuestionInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"qgdzs", "open", "get_question_info"}, ""))
|
pattern_Qgdzs_GetQuestionInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"qgdzs", "open", "get_question_info"}, ""))
|
||||||
|
pattern_Qgdzs_GetPointRecord_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"qgdzs", "auth", "point", "record"}, ""))
|
||||||
|
pattern_Qgdzs_GetPoint_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"qgdzs", "auth", "point", "info"}, ""))
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -718,4 +842,6 @@ var (
|
|||||||
forward_Qgdzs_QuicklyAnswerQuestion_0 = runtime.ForwardResponseMessage
|
forward_Qgdzs_QuicklyAnswerQuestion_0 = runtime.ForwardResponseMessage
|
||||||
forward_Qgdzs_GetRecord_0 = runtime.ForwardResponseMessage
|
forward_Qgdzs_GetRecord_0 = runtime.ForwardResponseMessage
|
||||||
forward_Qgdzs_GetQuestionInfo_0 = runtime.ForwardResponseMessage
|
forward_Qgdzs_GetQuestionInfo_0 = runtime.ForwardResponseMessage
|
||||||
|
forward_Qgdzs_GetPointRecord_0 = runtime.ForwardResponseMessage
|
||||||
|
forward_Qgdzs_GetPoint_0 = runtime.ForwardResponseMessage
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ type QgdzsClient interface {
|
|||||||
GetRecord(ctx context.Context, in *GetRecordReq, opts ...grpc.CallOption) (*GetRecordResp, error)
|
GetRecord(ctx context.Context, in *GetRecordReq, opts ...grpc.CallOption) (*GetRecordResp, error)
|
||||||
// 获取具体的题目
|
// 获取具体的题目
|
||||||
GetQuestionInfo(ctx context.Context, in *GetQuestionInfoReq, opts ...grpc.CallOption) (*GetQuestionInfoResp, error)
|
GetQuestionInfo(ctx context.Context, in *GetQuestionInfoReq, opts ...grpc.CallOption) (*GetQuestionInfoResp, error)
|
||||||
|
// ---------- 学识分 ----------
|
||||||
|
// 获取学识分获取记录
|
||||||
|
GetPointRecord(ctx context.Context, in *GetPointRecordReq, opts ...grpc.CallOption) (*GetPointRecordResp, error)
|
||||||
|
// 获取学识分
|
||||||
|
GetPoint(ctx context.Context, in *GetPointReq, opts ...grpc.CallOption) (*GetPointResp, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type qgdzsClient struct {
|
type qgdzsClient struct {
|
||||||
@@ -146,6 +151,24 @@ func (c *qgdzsClient) GetQuestionInfo(ctx context.Context, in *GetQuestionInfoRe
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *qgdzsClient) GetPointRecord(ctx context.Context, in *GetPointRecordReq, opts ...grpc.CallOption) (*GetPointRecordResp, error) {
|
||||||
|
out := new(GetPointRecordResp)
|
||||||
|
err := c.cc.Invoke(ctx, "/Qgdzs/GetPointRecord", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *qgdzsClient) GetPoint(ctx context.Context, in *GetPointReq, opts ...grpc.CallOption) (*GetPointResp, error) {
|
||||||
|
out := new(GetPointResp)
|
||||||
|
err := c.cc.Invoke(ctx, "/Qgdzs/GetPoint", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
// QgdzsServer is the server API for Qgdzs service.
|
// QgdzsServer is the server API for Qgdzs service.
|
||||||
// All implementations must embed UnimplementedQgdzsServer
|
// All implementations must embed UnimplementedQgdzsServer
|
||||||
// for forward compatibility
|
// for forward compatibility
|
||||||
@@ -174,6 +197,11 @@ type QgdzsServer interface {
|
|||||||
GetRecord(context.Context, *GetRecordReq) (*GetRecordResp, error)
|
GetRecord(context.Context, *GetRecordReq) (*GetRecordResp, error)
|
||||||
// 获取具体的题目
|
// 获取具体的题目
|
||||||
GetQuestionInfo(context.Context, *GetQuestionInfoReq) (*GetQuestionInfoResp, error)
|
GetQuestionInfo(context.Context, *GetQuestionInfoReq) (*GetQuestionInfoResp, error)
|
||||||
|
// ---------- 学识分 ----------
|
||||||
|
// 获取学识分获取记录
|
||||||
|
GetPointRecord(context.Context, *GetPointRecordReq) (*GetPointRecordResp, error)
|
||||||
|
// 获取学识分
|
||||||
|
GetPoint(context.Context, *GetPointReq) (*GetPointResp, error)
|
||||||
mustEmbedUnimplementedQgdzsServer()
|
mustEmbedUnimplementedQgdzsServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,6 +239,12 @@ func (UnimplementedQgdzsServer) GetRecord(context.Context, *GetRecordReq) (*GetR
|
|||||||
func (UnimplementedQgdzsServer) GetQuestionInfo(context.Context, *GetQuestionInfoReq) (*GetQuestionInfoResp, error) {
|
func (UnimplementedQgdzsServer) GetQuestionInfo(context.Context, *GetQuestionInfoReq) (*GetQuestionInfoResp, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method GetQuestionInfo not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method GetQuestionInfo not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedQgdzsServer) GetPointRecord(context.Context, *GetPointRecordReq) (*GetPointRecordResp, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetPointRecord not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedQgdzsServer) GetPoint(context.Context, *GetPointReq) (*GetPointResp, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetPoint not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedQgdzsServer) mustEmbedUnimplementedQgdzsServer() {}
|
func (UnimplementedQgdzsServer) mustEmbedUnimplementedQgdzsServer() {}
|
||||||
|
|
||||||
// UnsafeQgdzsServer may be embedded to opt out of forward compatibility for this service.
|
// UnsafeQgdzsServer may be embedded to opt out of forward compatibility for this service.
|
||||||
@@ -404,6 +438,42 @@ func _Qgdzs_GetQuestionInfo_Handler(srv interface{}, ctx context.Context, dec fu
|
|||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _Qgdzs_GetPointRecord_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetPointRecordReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(QgdzsServer).GetPointRecord(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/Qgdzs/GetPointRecord",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(QgdzsServer).GetPointRecord(ctx, req.(*GetPointRecordReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Qgdzs_GetPoint_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetPointReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(QgdzsServer).GetPoint(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/Qgdzs/GetPoint",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(QgdzsServer).GetPoint(ctx, req.(*GetPointReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
// Qgdzs_ServiceDesc is the grpc.ServiceDesc for Qgdzs service.
|
// Qgdzs_ServiceDesc is the grpc.ServiceDesc for Qgdzs service.
|
||||||
// It's only intended for direct use with grpc.RegisterService,
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
// and not to be introspected or modified (even as a copy)
|
// and not to be introspected or modified (even as a copy)
|
||||||
@@ -451,6 +521,14 @@ var Qgdzs_ServiceDesc = grpc.ServiceDesc{
|
|||||||
MethodName: "GetQuestionInfo",
|
MethodName: "GetQuestionInfo",
|
||||||
Handler: _Qgdzs_GetQuestionInfo_Handler,
|
Handler: _Qgdzs_GetQuestionInfo_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetPointRecord",
|
||||||
|
Handler: _Qgdzs_GetPointRecord_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetPoint",
|
||||||
|
Handler: _Qgdzs_GetPoint_Handler,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Streams: []grpc.StreamDesc{},
|
Streams: []grpc.StreamDesc{},
|
||||||
Metadata: "service_qgdzs.proto",
|
Metadata: "service_qgdzs.proto",
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ type EnterReq struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,proto3" json:"USN,omitempty"` // 用户ID
|
USN int64 `protobuf:"varint,1,opt,name=USN,proto3" json:"USN,omitempty"` // 用户ID
|
||||||
GatewaySID string `protobuf:"bytes,2,opt,name=GatewaySID,proto3" json:"GatewaySID,omitempty"` // 网关服务ID
|
GatewaySID int64 `protobuf:"varint,2,opt,name=GatewaySID,proto3" json:"GatewaySID,omitempty"` // 网关服务ID
|
||||||
InstanceID int32 `protobuf:"varint,3,opt,name=InstanceID,proto3" json:"InstanceID,omitempty"` // 副本ID
|
InstanceID int32 `protobuf:"varint,3,opt,name=InstanceID,proto3" json:"InstanceID,omitempty"` // 副本ID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,18 +63,18 @@ func (*EnterReq) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_scene_proto_rawDescGZIP(), []int{0}
|
return file_service_scene_proto_rawDescGZIP(), []int{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *EnterReq) GetUSN() string {
|
func (x *EnterReq) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *EnterReq) GetGatewaySID() string {
|
func (x *EnterReq) GetGatewaySID() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.GatewaySID
|
return x.GatewaySID
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *EnterReq) GetInstanceID() int32 {
|
func (x *EnterReq) GetInstanceID() int32 {
|
||||||
@@ -89,8 +89,8 @@ type EnterResp struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
SceneSID string `protobuf:"bytes,1,opt,name=SceneSID,proto3" json:"SceneSID,omitempty"` // 场景服务ID
|
SceneSID int64 `protobuf:"varint,1,opt,name=SceneSID,proto3" json:"SceneSID,omitempty"` // 场景服务ID
|
||||||
UniqueNo string `protobuf:"bytes,2,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
|
UniqueNo int64 `protobuf:"varint,2,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
|
||||||
MessageID int32 `protobuf:"varint,3,opt,name=MessageID,proto3" json:"MessageID,omitempty"` // 发送给客户端的消息ID
|
MessageID int32 `protobuf:"varint,3,opt,name=MessageID,proto3" json:"MessageID,omitempty"` // 发送给客户端的消息ID
|
||||||
Payload []byte `protobuf:"bytes,4,opt,name=Payload,proto3" json:"Payload,omitempty"` // 消息负载
|
Payload []byte `protobuf:"bytes,4,opt,name=Payload,proto3" json:"Payload,omitempty"` // 消息负载
|
||||||
}
|
}
|
||||||
@@ -127,18 +127,18 @@ func (*EnterResp) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_scene_proto_rawDescGZIP(), []int{1}
|
return file_service_scene_proto_rawDescGZIP(), []int{1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *EnterResp) GetSceneSID() string {
|
func (x *EnterResp) GetSceneSID() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.SceneSID
|
return x.SceneSID
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *EnterResp) GetUniqueNo() string {
|
func (x *EnterResp) GetUniqueNo() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.UniqueNo
|
return x.UniqueNo
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *EnterResp) GetMessageID() int32 {
|
func (x *EnterResp) GetMessageID() int32 {
|
||||||
@@ -160,8 +160,8 @@ type LeaveReq struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,proto3" json:"USN,omitempty"` // 用户ID
|
USN int64 `protobuf:"varint,1,opt,name=USN,proto3" json:"USN,omitempty"` // 用户ID
|
||||||
UniqueNo string `protobuf:"bytes,2,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
|
UniqueNo int64 `protobuf:"varint,2,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *LeaveReq) Reset() {
|
func (x *LeaveReq) Reset() {
|
||||||
@@ -196,18 +196,18 @@ func (*LeaveReq) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_scene_proto_rawDescGZIP(), []int{2}
|
return file_service_scene_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *LeaveReq) GetUSN() string {
|
func (x *LeaveReq) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *LeaveReq) GetUniqueNo() string {
|
func (x *LeaveReq) GetUniqueNo() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.UniqueNo
|
return x.UniqueNo
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type LeaveResp struct {
|
type LeaveResp struct {
|
||||||
@@ -253,8 +253,8 @@ type ActionReq struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
UniqueNo string `protobuf:"bytes,1,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
|
UniqueNo int64 `protobuf:"varint,1,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
|
||||||
USN string `protobuf:"bytes,2,opt,name=USN,proto3" json:"USN,omitempty"` // 用户ID
|
USN int64 `protobuf:"varint,2,opt,name=USN,proto3" json:"USN,omitempty"` // 用户ID
|
||||||
Action int32 `protobuf:"varint,3,opt,name=Action,proto3" json:"Action,omitempty"` // 指令ID
|
Action int32 `protobuf:"varint,3,opt,name=Action,proto3" json:"Action,omitempty"` // 指令ID
|
||||||
DirX int32 `protobuf:"zigzag32,4,opt,name=DirX,proto3" json:"DirX,omitempty"` // 移动-X方向(×1000 缩放)
|
DirX int32 `protobuf:"zigzag32,4,opt,name=DirX,proto3" json:"DirX,omitempty"` // 移动-X方向(×1000 缩放)
|
||||||
DirY int32 `protobuf:"zigzag32,5,opt,name=DirY,proto3" json:"DirY,omitempty"` // 移动-Y方向(×1000 缩放)
|
DirY int32 `protobuf:"zigzag32,5,opt,name=DirY,proto3" json:"DirY,omitempty"` // 移动-Y方向(×1000 缩放)
|
||||||
@@ -293,18 +293,18 @@ func (*ActionReq) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_scene_proto_rawDescGZIP(), []int{4}
|
return file_service_scene_proto_rawDescGZIP(), []int{4}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ActionReq) GetUniqueNo() string {
|
func (x *ActionReq) GetUniqueNo() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.UniqueNo
|
return x.UniqueNo
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ActionReq) GetUSN() string {
|
func (x *ActionReq) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ActionReq) GetAction() int32 {
|
func (x *ActionReq) GetAction() int32 {
|
||||||
@@ -379,27 +379,27 @@ var file_service_scene_proto_rawDesc = []byte{
|
|||||||
0x0a, 0x13, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x73, 0x63, 0x65, 0x6e, 0x65, 0x2e,
|
0x0a, 0x13, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x73, 0x63, 0x65, 0x6e, 0x65, 0x2e,
|
||||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x72, 0x73, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e,
|
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x72, 0x73, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e,
|
||||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5c, 0x0a, 0x08, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52,
|
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5c, 0x0a, 0x08, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52,
|
||||||
0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52,
|
||||||
0x03, 0x55, 0x53, 0x4e, 0x12, 0x1e, 0x0a, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53,
|
0x03, 0x55, 0x53, 0x4e, 0x12, 0x1e, 0x0a, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53,
|
||||||
0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61,
|
0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61,
|
||||||
0x79, 0x53, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
|
0x79, 0x53, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
|
||||||
0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e,
|
0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e,
|
||||||
0x63, 0x65, 0x49, 0x44, 0x22, 0x7b, 0x0a, 0x09, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73,
|
0x63, 0x65, 0x49, 0x44, 0x22, 0x7b, 0x0a, 0x09, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73,
|
||||||
0x70, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x53, 0x49, 0x44, 0x18, 0x01, 0x20,
|
0x70, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x53, 0x49, 0x44, 0x18, 0x01, 0x20,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x08, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x53, 0x49, 0x44, 0x12, 0x1a, 0x0a,
|
0x01, 0x28, 0x03, 0x52, 0x08, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x53, 0x49, 0x44, 0x12, 0x1a, 0x0a,
|
||||||
0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52,
|
||||||
0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x4d, 0x65, 0x73,
|
0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x4d, 0x65, 0x73,
|
||||||
0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x4d, 0x65,
|
0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x4d, 0x65,
|
||||||
0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f,
|
0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f,
|
||||||
0x61, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61,
|
0x61, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61,
|
||||||
0x64, 0x22, 0x38, 0x0a, 0x08, 0x4c, 0x65, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a,
|
0x64, 0x22, 0x38, 0x0a, 0x08, 0x4c, 0x65, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a,
|
||||||
0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x55, 0x53, 0x4e, 0x12,
|
0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x55, 0x53, 0x4e, 0x12,
|
||||||
0x1a, 0x0a, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28,
|
0x1a, 0x0a, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||||
0x09, 0x52, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x22, 0x0b, 0x0a, 0x09, 0x4c,
|
0x03, 0x52, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x22, 0x0b, 0x0a, 0x09, 0x4c,
|
||||||
0x65, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x93, 0x01, 0x0a, 0x09, 0x41, 0x63, 0x74,
|
0x65, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x93, 0x01, 0x0a, 0x09, 0x41, 0x63, 0x74,
|
||||||
0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65,
|
0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65,
|
||||||
0x4e, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65,
|
0x4e, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65,
|
||||||
0x4e, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x4e, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52,
|
||||||
0x03, 0x55, 0x53, 0x4e, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03,
|
0x03, 0x55, 0x53, 0x4e, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03,
|
||||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04,
|
0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04,
|
||||||
0x44, 0x69, 0x72, 0x58, 0x18, 0x04, 0x20, 0x01, 0x28, 0x11, 0x52, 0x04, 0x44, 0x69, 0x72, 0x58,
|
0x44, 0x69, 0x72, 0x58, 0x18, 0x04, 0x20, 0x01, 0x28, 0x11, 0x52, 0x04, 0x44, 0x69, 0x72, 0x58,
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ type PhoneLoginResp struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,json=usn,proto3" json:"USN,omitempty"` // 用户ID
|
USN int64 `protobuf:"varint,1,opt,name=USN,json=usn,proto3" json:"USN,omitempty"` // 用户ID
|
||||||
Name string `protobuf:"bytes,2,opt,name=Name,json=name,proto3" json:"Name,omitempty"` // 用户名
|
Name string `protobuf:"bytes,2,opt,name=Name,json=name,proto3" json:"Name,omitempty"` // 用户名
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,11 +119,11 @@ func (*PhoneLoginResp) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_user_proto_rawDescGZIP(), []int{1}
|
return file_service_user_proto_rawDescGZIP(), []int{1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *PhoneLoginResp) GetUSN() string {
|
func (x *PhoneLoginResp) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *PhoneLoginResp) GetName() string {
|
func (x *PhoneLoginResp) GetName() string {
|
||||||
@@ -186,7 +186,7 @@ type WxMiniLoginResp struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,json=usn,proto3" json:"USN,omitempty"` // 用户ID
|
USN int64 `protobuf:"varint,1,opt,name=USN,json=usn,proto3" json:"USN,omitempty"` // 用户ID
|
||||||
Name string `protobuf:"bytes,2,opt,name=Name,json=name,proto3" json:"Name,omitempty"` // 用户名
|
Name string `protobuf:"bytes,2,opt,name=Name,json=name,proto3" json:"Name,omitempty"` // 用户名
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,11 +222,11 @@ func (*WxMiniLoginResp) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_user_proto_rawDescGZIP(), []int{3}
|
return file_service_user_proto_rawDescGZIP(), []int{3}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *WxMiniLoginResp) GetUSN() string {
|
func (x *WxMiniLoginResp) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *WxMiniLoginResp) GetName() string {
|
func (x *WxMiniLoginResp) GetName() string {
|
||||||
@@ -242,7 +242,7 @@ type GetUserInfoReq struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,json=usn,proto3" json:"USN,omitempty"`
|
USN int64 `protobuf:"varint,1,opt,name=USN,json=usn,proto3" json:"USN,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *GetUserInfoReq) Reset() {
|
func (x *GetUserInfoReq) Reset() {
|
||||||
@@ -277,11 +277,11 @@ func (*GetUserInfoReq) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_user_proto_rawDescGZIP(), []int{4}
|
return file_service_user_proto_rawDescGZIP(), []int{4}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *GetUserInfoReq) GetUSN() string {
|
func (x *GetUserInfoReq) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetUserInfoResp struct {
|
type GetUserInfoResp struct {
|
||||||
@@ -289,7 +289,7 @@ type GetUserInfoResp struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,json=usn,proto3" json:"USN,omitempty"`
|
USN int64 `protobuf:"varint,1,opt,name=USN,json=usn,proto3" json:"USN,omitempty"`
|
||||||
Name string `protobuf:"bytes,2,opt,name=Name,json=name,proto3" json:"Name,omitempty"`
|
Name string `protobuf:"bytes,2,opt,name=Name,json=name,proto3" json:"Name,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,11 +325,11 @@ func (*GetUserInfoResp) Descriptor() ([]byte, []int) {
|
|||||||
return file_service_user_proto_rawDescGZIP(), []int{5}
|
return file_service_user_proto_rawDescGZIP(), []int{5}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *GetUserInfoResp) GetUSN() string {
|
func (x *GetUserInfoResp) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *GetUserInfoResp) GetName() string {
|
func (x *GetUserInfoResp) GetName() string {
|
||||||
@@ -351,19 +351,19 @@ var file_service_user_proto_rawDesc = []byte{
|
|||||||
0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f,
|
0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f,
|
||||||
0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x36,
|
0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x36,
|
||||||
0x0a, 0x0e, 0x50, 0x68, 0x6f, 0x6e, 0x65, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70,
|
0x0a, 0x0e, 0x50, 0x68, 0x6f, 0x6e, 0x65, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70,
|
||||||
0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75,
|
0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75,
|
||||||
0x73, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
0x73, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x24, 0x0a, 0x0e, 0x57, 0x78, 0x4d, 0x69, 0x6e, 0x69,
|
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x24, 0x0a, 0x0e, 0x57, 0x78, 0x4d, 0x69, 0x6e, 0x69,
|
||||||
0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65,
|
0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65,
|
||||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x37, 0x0a, 0x0f,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x37, 0x0a, 0x0f,
|
||||||
0x57, 0x78, 0x4d, 0x69, 0x6e, 0x69, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12,
|
0x57, 0x78, 0x4d, 0x69, 0x6e, 0x69, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12,
|
||||||
0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x73,
|
0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x73,
|
||||||
0x6e, 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x6e, 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x22, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72,
|
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x22, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72,
|
||||||
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01,
|
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53, 0x4e, 0x18, 0x01,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x73, 0x6e, 0x22, 0x37, 0x0a, 0x0f, 0x47, 0x65, 0x74,
|
0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x73, 0x6e, 0x22, 0x37, 0x0a, 0x0f, 0x47, 0x65, 0x74,
|
||||||
0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03,
|
0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03,
|
||||||
0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x73, 0x6e, 0x12, 0x12,
|
0x55, 0x53, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x73, 0x6e, 0x12, 0x12,
|
||||||
0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
|
0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
|
||||||
0x6d, 0x65, 0x32, 0xb9, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x2f, 0x0a, 0x0a, 0x50,
|
0x6d, 0x65, 0x32, 0xb9, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x2f, 0x0a, 0x0a, 0x50,
|
||||||
0x68, 0x6f, 0x6e, 0x65, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x0e, 0x2e, 0x50, 0x68, 0x6f, 0x6e,
|
0x68, 0x6f, 0x6e, 0x65, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x0e, 0x2e, 0x50, 0x68, 0x6f, 0x6e,
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ type PositionInfo struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
USN string `protobuf:"bytes,1,opt,name=USN,proto3" json:"USN,omitempty"`
|
USN int64 `protobuf:"varint,1,opt,name=USN,proto3" json:"USN,omitempty"`
|
||||||
X int32 `protobuf:"zigzag32,2,opt,name=X,proto3" json:"X,omitempty"`
|
X int32 `protobuf:"zigzag32,2,opt,name=X,proto3" json:"X,omitempty"`
|
||||||
Y int32 `protobuf:"zigzag32,3,opt,name=Y,proto3" json:"Y,omitempty"`
|
Y int32 `protobuf:"zigzag32,3,opt,name=Y,proto3" json:"Y,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -296,11 +296,11 @@ func (*PositionInfo) Descriptor() ([]byte, []int) {
|
|||||||
return file_action_proto_rawDescGZIP(), []int{3}
|
return file_action_proto_rawDescGZIP(), []int{3}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *PositionInfo) GetUSN() string {
|
func (x *PositionInfo) GetUSN() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.USN
|
return x.USN
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *PositionInfo) GetX() int32 {
|
func (x *PositionInfo) GetX() int32 {
|
||||||
@@ -388,7 +388,7 @@ var file_action_proto_rawDesc = []byte{
|
|||||||
0x12, 0x18, 0x0a, 0x07, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x18, 0x06, 0x20, 0x01, 0x28,
|
0x12, 0x18, 0x0a, 0x07, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x18, 0x06, 0x20, 0x01, 0x28,
|
||||||
0x05, 0x52, 0x07, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x22, 0x3c, 0x0a, 0x0c, 0x50, 0x6f,
|
0x05, 0x52, 0x07, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x22, 0x3c, 0x0a, 0x0c, 0x50, 0x6f,
|
||||||
0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53,
|
0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x53,
|
||||||
0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x55, 0x53, 0x4e, 0x12, 0x0c, 0x0a, 0x01,
|
0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x55, 0x53, 0x4e, 0x12, 0x0c, 0x0a, 0x01,
|
||||||
0x58, 0x18, 0x02, 0x20, 0x01, 0x28, 0x11, 0x52, 0x01, 0x58, 0x12, 0x0c, 0x0a, 0x01, 0x59, 0x18,
|
0x58, 0x18, 0x02, 0x20, 0x01, 0x28, 0x11, 0x52, 0x01, 0x58, 0x12, 0x0c, 0x0a, 0x01, 0x59, 0x18,
|
||||||
0x03, 0x20, 0x01, 0x28, 0x11, 0x52, 0x01, 0x59, 0x22, 0x31, 0x0a, 0x0c, 0x53, 0x32, 0x43, 0x5f,
|
0x03, 0x20, 0x01, 0x28, 0x11, 0x52, 0x01, 0x59, 0x22, 0x31, 0x0a, 0x0c, 0x53, 0x32, 0x43, 0x5f,
|
||||||
0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f,
|
0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f,
|
||||||
|
|||||||
17
utils/jwt.go
17
utils/jwt.go
@@ -1,19 +1,17 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Claims struct {
|
type Claims struct {
|
||||||
USN string `json:"usn"`
|
USN int64 `json:"usn"`
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenToken(usn string, secret string, expires time.Duration) (string, error) {
|
func GenToken(usn int64, secret string, expires time.Duration) (string, error) {
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, Claims{
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, Claims{
|
||||||
USN: usn,
|
USN: usn,
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
@@ -39,14 +37,3 @@ func ParseToken(tokenString string, secret string) (*Claims, error) {
|
|||||||
}
|
}
|
||||||
return claims, nil
|
return claims, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShouldBindUsn(ctx context.Context, usn *string) bool {
|
|
||||||
if md, ok := metadata.FromIncomingContext(ctx); ok {
|
|
||||||
usnArr := md.Get("X-Usn")
|
|
||||||
if len(usnArr) == 0 || usnArr[0] == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
*usn = usnArr[0]
|
|
||||||
}
|
|
||||||
return *usn != ""
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,3 +21,8 @@ func StringToInt64(s string) int64 {
|
|||||||
}
|
}
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Int64ToString converts int64 to string
|
||||||
|
func Int64ToString(i int64) string {
|
||||||
|
return strconv.FormatInt(i, 10)
|
||||||
|
}
|
||||||
|
|||||||
29
utils/session.go
Normal file
29
utils/session.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserSession struct {
|
||||||
|
USN int64 `json:"usn" redis:"usn"`
|
||||||
|
IP string `json:"ip" redis:"ip"`
|
||||||
|
UserAgent string `json:"ua" redis:"ua"`
|
||||||
|
AccessToken string `json:"at" redis:"at"`
|
||||||
|
RefreshToken string `json:"rt" redis:"rt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (us *UserSession) GetUsnKey() string {
|
||||||
|
return "usn"
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShouldBindUsn(ctx context.Context, usn *int64) bool {
|
||||||
|
if md, ok := metadata.FromIncomingContext(ctx); ok {
|
||||||
|
usnArr := md.Get("X-Usn")
|
||||||
|
if len(usnArr) == 0 || usnArr[0] == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
*usn = StringToInt64(usnArr[0])
|
||||||
|
}
|
||||||
|
return *usn != 0
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user