diff --git a/cmd/robot/robot.go b/cmd/robot/robot.go index fe6ce05ec..3f916765e 100644 --- a/cmd/robot/robot.go +++ b/cmd/robot/robot.go @@ -152,7 +152,7 @@ func (r *Robot) AccountRegister(account string) { //打印响应 func printReply(msg *pb.UserMessage, rsp interface{}) { - log.Printf("rsp [%s.%s] [%d] [%v]", msg.MainType, msg.SubType, msg.Code, rsp) + log.Printf("rsp [%s.%s] [%v]", msg.MainType, msg.SubType, rsp) } //方法参数跟踪 diff --git a/comm/core.go b/comm/core.go index 8c515c501..e55511e07 100644 --- a/comm/core.go +++ b/comm/core.go @@ -73,6 +73,12 @@ const ( LogHandleType_Delete LogHandleType = "delete" ) +//Api Check 错误返回结构 +type ErrorCode struct { + Code pb.ErrorCode + Data interface{} +} + //用户会话 type IUserSession interface { GetSessionId() string @@ -82,7 +88,7 @@ type IUserSession interface { IsLogin() bool Bind(uid string, wokerId string) (err error) UnBind() (err error) - SendMsg(mainType, subType string, code pb.ErrorCode, msg proto.Message) (err error) + SendMsg(mainType, subType string, msg proto.Message) (err error) Close() (err error) ToString() string } diff --git a/comm/usersession.go b/comm/usersession.go index 25836cc53..ce18b1428 100644 --- a/comm/usersession.go +++ b/comm/usersession.go @@ -86,15 +86,14 @@ func (this *UserSession) UnBind() (err error) { } //向用户发送消息 -func (this *UserSession) SendMsg(mainType, subType string, code pb.ErrorCode, msg proto.Message) (err error) { +func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) { reply := &pb.RPCMessageReply{} data, _ := ptypes.MarshalAny(msg) - log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Code:%d Data: %v", this.UserId, code, msg) + log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg) if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{ UserSessionId: this.SessionId, MainType: mainType, SubType: subType, - Code: code, Data: data, }, reply); err != nil { log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err) diff --git a/lego/sys/gin/binding/form_mapping.go b/lego/sys/gin/binding/form_mapping.go index a5798633f..29b85cb82 100644 --- a/lego/sys/gin/binding/form_mapping.go +++ b/lego/sys/gin/binding/form_mapping.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "go_dreamfactory/lego/utils/convert" + "go_dreamfactory/lego/utils/codec" ) var ( @@ -236,9 +236,9 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel case time.Time: return setTimeField(val, field, value) } - return json.Unmarshal(convert.StringToBytes(val), value.Addr().Interface()) + return json.Unmarshal(codec.StringToBytes(val), value.Addr().Interface()) case reflect.Map: - return json.Unmarshal(convert.StringToBytes(val), value.Addr().Interface()) + return json.Unmarshal(codec.StringToBytes(val), value.Addr().Interface()) default: return errUnknownType } diff --git a/lego/sys/gin/engine/engine.go b/lego/sys/gin/engine/engine.go index ad96b617f..ebe61d14c 100644 --- a/lego/sys/gin/engine/engine.go +++ b/lego/sys/gin/engine/engine.go @@ -9,7 +9,7 @@ import ( "sync" "go_dreamfactory/lego/sys/gin/render" - "go_dreamfactory/lego/utils/convert" + "go_dreamfactory/lego/utils/codec" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" @@ -418,7 +418,7 @@ func (this *Engine) redirectFixedPath(c *Context, root *node, trailingSlash bool rPath := req.URL.Path if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(rPath), trailingSlash); ok { - req.URL.Path = convert.BytesToString(fixedPath) + req.URL.Path = codec.BytesToString(fixedPath) this.redirectRequest(c) return true } diff --git a/lego/sys/gin/engine/tree.go b/lego/sys/gin/engine/tree.go index de840910e..e921fe944 100644 --- a/lego/sys/gin/engine/tree.go +++ b/lego/sys/gin/engine/tree.go @@ -7,7 +7,7 @@ import ( "unicode" "unicode/utf8" - "go_dreamfactory/lego/utils/convert" + "go_dreamfactory/lego/utils/codec" ) var ( @@ -107,7 +107,7 @@ walk: n.children = []*node{&child} // []byte for proper unicode char conversion, see #65 - n.indices = convert.BytesToString([]byte{n.path[i]}) + n.indices = codec.BytesToString([]byte{n.path[i]}) n.path = path[:i] n.handlers = nil n.wildChild = false @@ -140,7 +140,7 @@ walk: // Otherwise insert it if c != ':' && c != '*' && n.nType != catchAll { // []byte for proper unicode char conversion, see #65 - n.indices += convert.BytesToString([]byte{c}) + n.indices += codec.BytesToString([]byte{c}) child := &node{ fullPath: fullPath, } @@ -820,14 +820,14 @@ func findWildcard(path string) (wildcard string, i int, valid bool) { func countParams(path string) uint16 { var n uint16 - s := convert.StringToBytes(path) + s := codec.StringToBytes(path) n += uint16(bytes.Count(s, strColon)) n += uint16(bytes.Count(s, strStar)) return n } func countSections(path string) uint16 { - s := convert.StringToBytes(path) + s := codec.StringToBytes(path) return uint16(bytes.Count(s, strSlash)) } func min(a, b int) int { diff --git a/lego/sys/gin/render/json.go b/lego/sys/gin/render/json.go index 6db6fae97..460bd0211 100644 --- a/lego/sys/gin/render/json.go +++ b/lego/sys/gin/render/json.go @@ -7,7 +7,7 @@ import ( "html/template" "net/http" - "go_dreamfactory/lego/utils/convert" + "go_dreamfactory/lego/utils/codec" ) // JSON contains the given interface object. @@ -96,9 +96,9 @@ func (r SecureJSON) Render(w http.ResponseWriter) error { return err } // if the jsonBytes is array values - if bytes.HasPrefix(jsonBytes, convert.StringToBytes("[")) && bytes.HasSuffix(jsonBytes, - convert.StringToBytes("]")) { - if _, err = w.Write(convert.StringToBytes(r.Prefix)); err != nil { + if bytes.HasPrefix(jsonBytes, codec.StringToBytes("[")) && bytes.HasSuffix(jsonBytes, + codec.StringToBytes("]")) { + if _, err = w.Write(codec.StringToBytes(r.Prefix)); err != nil { return err } } @@ -125,11 +125,11 @@ func (r JsonpJSON) Render(w http.ResponseWriter) (err error) { } callback := template.JSEscapeString(r.Callback) - if _, err = w.Write(convert.StringToBytes(callback)); err != nil { + if _, err = w.Write(codec.StringToBytes(callback)); err != nil { return err } - if _, err = w.Write(convert.StringToBytes("(")); err != nil { + if _, err = w.Write(codec.StringToBytes("(")); err != nil { return err } @@ -137,7 +137,7 @@ func (r JsonpJSON) Render(w http.ResponseWriter) (err error) { return err } - if _, err = w.Write(convert.StringToBytes(");")); err != nil { + if _, err = w.Write(codec.StringToBytes(");")); err != nil { return err } @@ -158,7 +158,7 @@ func (r AsciiJSON) Render(w http.ResponseWriter) (err error) { } var buffer bytes.Buffer - for _, r := range convert.BytesToString(ret) { + for _, r := range codec.BytesToString(ret) { cvt := string(r) if r >= 128 { cvt = fmt.Sprintf("\\u%04x", int64(r)) diff --git a/lego/sys/gin/render/text.go b/lego/sys/gin/render/text.go index a516da5a6..5a9e6bcba 100644 --- a/lego/sys/gin/render/text.go +++ b/lego/sys/gin/render/text.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "go_dreamfactory/lego/utils/convert" + "go_dreamfactory/lego/utils/codec" ) // String contains the given interface object slice and its format. @@ -32,6 +32,6 @@ func WriteString(w http.ResponseWriter, format string, data []interface{}) (err _, err = fmt.Fprintf(w, format, data...) return } - _, err = w.Write(convert.StringToBytes(format)) + _, err = w.Write(codec.StringToBytes(format)) return } diff --git a/lego/sys/redis/cluster/core.go b/lego/sys/redis/cluster/core.go index 7d1ccdf91..3c5148b85 100644 --- a/lego/sys/redis/cluster/core.go +++ b/lego/sys/redis/cluster/core.go @@ -2,14 +2,15 @@ package cluster import ( "context" + "go_dreamfactory/lego/utils/codec" "time" "github.com/go-redis/redis/v8" ) func NewSys(RedisUrl []string, RedisPassword string, timeOut time.Duration, - encode func(value interface{}) (result []byte, err error), - decode func(value []byte, result interface{}) (err error), + encode codec.IEncoder, + decode codec.IDecoder, ) (sys *Redis, err error) { var ( client *redis.ClusterClient @@ -21,8 +22,8 @@ func NewSys(RedisUrl []string, RedisPassword string, timeOut time.Duration, sys = &Redis{ client: client, timeOut: timeOut, - Encode: encode, - Decode: decode, + encode: encode, + decode: decode, } _, err = sys.Ping() return @@ -31,8 +32,8 @@ func NewSys(RedisUrl []string, RedisPassword string, timeOut time.Duration, type Redis struct { client *redis.ClusterClient timeOut time.Duration - Encode func(value interface{}) (result []byte, err error) - Decode func(value []byte, result interface{}) (err error) + encode codec.IEncoder + decode codec.IDecoder } func (this *Redis) getContext() (ctx context.Context) { diff --git a/lego/sys/redis/cluster/hash.go b/lego/sys/redis/cluster/hash.go index 875e1235c..6654b2a01 100644 --- a/lego/sys/redis/cluster/hash.go +++ b/lego/sys/redis/cluster/hash.go @@ -28,13 +28,34 @@ func (this *Redis) HExists(key string, field string) (result bool, err error) { return } +/* +Redis Hmset 命令用于同时将多个 field-value (字段-值)对设置到哈希表中。 +此命令会覆盖哈希表中已存在的字段。 +如果哈希表不存在,会创建一个空哈希表,并执行 HMSET 操作 +*/ +func (this *Redis) HMSet(key string, v interface{}) (err error) { + agrs := make([]interface{}, 0) + agrs = append(agrs, "HMSET") + agrs = append(agrs, key) + var data map[string][]byte + if data, err = this.encode.EncoderToMap(v); err != nil { + return + } + for k, v := range data { + result, _ := this.encode.Encoder(v) + agrs = append(agrs, k, result) + } + err = this.client.Do(this.getContext(), agrs...).Err() + return +} + /* Redis Hget 命令用于返回哈希表中指定字段的值 */ func (this *Redis) HGet(key string, field string, value interface{}) (err error) { var resultvalue string if resultvalue = this.client.Do(this.getContext(), "HSET", key, field).String(); resultvalue != string(redis.Nil) { - err = this.Decode([]byte(resultvalue), value) + err = this.decode.Decoder([]byte(resultvalue), value) } return } @@ -43,18 +64,12 @@ func (this *Redis) HGet(key string, field string, value interface{}) (err error) Redis Hgetall 命令用于返回哈希表中,所有的字段和值。 在返回值里,紧跟每个字段名(field name)之后是字段的值(value),所以返回值的长度是哈希表大小的两倍 */ -func (this *Redis) HGetAll(key string, valuetype reflect.Type) (result []interface{}, err error) { - cmd := redis.NewStringSliceCmd(this.getContext(), "HGETALL", key) +func (this *Redis) HGetAll(key string, v interface{}) (err error) { + cmd := redis.NewStringStringMapCmd(this.getContext(), "HGETALL", key) this.client.Process(this.getContext(), cmd) - var _result []string + var _result map[string]string if _result, err = cmd.Result(); err == nil { - result = make([]interface{}, len(_result)) - for i, v := range _result { - temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { - result[i] = temp - } - } + err = this.decode.DecoderMap(_result, v) } return } @@ -117,7 +132,7 @@ func (this *Redis) HMGet(key string, valuetype reflect.Type, fields ...string) ( result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -125,23 +140,6 @@ func (this *Redis) HMGet(key string, valuetype reflect.Type, fields ...string) ( return } -/* -Redis Hmset 命令用于同时将多个 field-value (字段-值)对设置到哈希表中。 -此命令会覆盖哈希表中已存在的字段。 -如果哈希表不存在,会创建一个空哈希表,并执行 HMSET 操作 -*/ -func (this *Redis) HMSet(key string, value map[string]interface{}) (err error) { - agrs := make([]interface{}, 0) - agrs = append(agrs, "HMSET") - agrs = append(agrs, key) - for k, v := range value { - result, _ := this.Encode(v) - agrs = append(agrs, k, result) - } - err = this.client.Do(this.getContext(), agrs...).Err() - return -} - /* Redis Hset 命令用于为哈希表中的字段赋值 如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作 @@ -149,7 +147,7 @@ Redis Hset 命令用于为哈希表中的字段赋值 */ func (this *Redis) HSet(key string, field string, value interface{}) (err error) { var resultvalue []byte - if resultvalue, err = this.Encode(value); err == nil { + if resultvalue, err = this.encode.Encoder(value); err == nil { err = this.client.Do(this.getContext(), "HSET", key, field, resultvalue).Err() } return @@ -163,7 +161,7 @@ Redis Hsetnx 命令用于为哈希表中不存在的的字段赋值 */ func (this *Redis) HSetNX(key string, field string, value interface{}) (err error) { var resultvalue []byte - if resultvalue, err = this.Encode(value); err == nil { + if resultvalue, err = this.encode.Encoder(value); err == nil { err = this.client.Do(this.getContext(), "HSETNX", key, field, resultvalue).Err() } return diff --git a/lego/sys/redis/cluster/list.go b/lego/sys/redis/cluster/list.go index 9e5a98c7a..ead22abfc 100644 --- a/lego/sys/redis/cluster/list.go +++ b/lego/sys/redis/cluster/list.go @@ -13,7 +13,7 @@ Redis Lindex 命令用于通过索引获取列表中的元素。你也可以使 func (this *Redis) Lindex(key string, value interface{}) (err error) { var data string if data = this.client.Do(this.getContext(), "LINDEX", key).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), value) + err = this.decode.Decoder([]byte(data), value) } else { err = fmt.Errorf(string(redis.Nil)) } @@ -30,8 +30,8 @@ func (this *Redis) Linsert(key string, isbefore bool, tager interface{}, value i tagervalue []byte resultvalue []byte ) - if tagervalue, err = this.Encode(tager); err == nil { - if resultvalue, err = this.Encode(value); err == nil { + if tagervalue, err = this.encode.Encoder(tager); err == nil { + if resultvalue, err = this.encode.Encoder(value); err == nil { if isbefore { err = this.client.Do(this.getContext(), "LINSERT", key, "BEFORE", tagervalue, resultvalue).Err() } else { @@ -56,7 +56,7 @@ Redis Lpop 命令用于移除并返回列表的第一个元素 func (this *Redis) LPop(key string, value interface{}) (err error) { var data string if data = this.client.Do(this.getContext(), "LPOP", key).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), value) + err = this.decode.Decoder([]byte(data), value) } else { err = fmt.Errorf(string(redis.Nil)) } @@ -70,7 +70,7 @@ func (this *Redis) LPush(key string, values ...interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "LPUSH") for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -84,7 +84,7 @@ func (this *Redis) LPushX(key string, values ...interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "LPUSHX") for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -103,7 +103,7 @@ func (this *Redis) LRange(key string, start, end int, valuetype reflect.Type) (r result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -120,7 +120,7 @@ count = 0 : 移除表中所有与 VALUE 相等的值 */ func (this *Redis) LRem(key string, count int, target interface{}) (err error) { var resultvalue []byte - if resultvalue, err = this.Encode(target); err == nil { + if resultvalue, err = this.encode.Encoder(target); err == nil { err = this.client.Do(this.getContext(), "LREM", key, count, resultvalue).Err() } return @@ -132,7 +132,7 @@ Redis Lset 通过索引来设置元素的值。 */ func (this *Redis) LSet(key string, index int, value interface{}) (err error) { var resultvalue []byte - if resultvalue, err = this.Encode(value); err == nil { + if resultvalue, err = this.encode.Encoder(value); err == nil { err = this.client.Do(this.getContext(), "LSET", key, index, resultvalue).Err() } return @@ -154,7 +154,7 @@ Redis Rpop 命令用于移除列表的最后一个元素,返回值为移除的 func (this *Redis) Rpop(key string, value interface{}) (err error) { var data string if data = this.client.Do(this.getContext(), "RPOP", key).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), value) + err = this.decode.Decoder([]byte(data), value) } else { err = fmt.Errorf(string(redis.Nil)) } @@ -167,7 +167,7 @@ Redis Rpoplpush 命令用于移除列表的最后一个元素,并将该元素 func (this *Redis) RPopLPush(oldkey string, newkey string, value interface{}) (err error) { var data string if data = this.client.Do(this.getContext(), "RPOPLPUSH", oldkey, newkey).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), value) + err = this.decode.Decoder([]byte(data), value) } else { err = fmt.Errorf(string(redis.Nil)) } @@ -183,7 +183,7 @@ func (this *Redis) RPush(key string, values ...interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "RPUSH") for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -197,7 +197,7 @@ func (this *Redis) RPushX(key string, values ...interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "RPUSHX") for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() diff --git a/lego/sys/redis/cluster/set.go b/lego/sys/redis/cluster/set.go index 74d5561f6..32d49c9f6 100644 --- a/lego/sys/redis/cluster/set.go +++ b/lego/sys/redis/cluster/set.go @@ -12,7 +12,7 @@ func (this *Redis) SAdd(key string, values ...interface{}) (err error) { agrs = append(agrs, "SADD") agrs = append(agrs, key) for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -39,7 +39,7 @@ func (this *Redis) SDiff(valuetype reflect.Type, keys ...string) (result []inter result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -65,7 +65,7 @@ func (this *Redis) SInter(valuetype reflect.Type, keys ...string) (result []inte result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -99,7 +99,7 @@ func (this *Redis) SMembers(valuetype reflect.Type, key string) (result []interf result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -160,7 +160,7 @@ func (this *Redis) SUnion(valuetype reflect.Type, keys ...string) (result []inte result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } diff --git a/lego/sys/redis/cluster/string.go b/lego/sys/redis/cluster/string.go index 17fc6f1a9..bcdf9afd9 100644 --- a/lego/sys/redis/cluster/string.go +++ b/lego/sys/redis/cluster/string.go @@ -13,7 +13,7 @@ import ( */ func (this *Redis) Set(key string, value interface{}, expiration time.Duration) (err error) { var result []byte - if result, err = this.Encode(value); err == nil { + if result, err = this.encode.Encoder(value); err == nil { err = this.client.Set(this.getContext(), string(key), result, expiration).Err() } return @@ -40,7 +40,7 @@ func (this *Redis) MSet(keyvalues map[string]interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "MSET") for k, v := range keyvalues { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, k, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -54,7 +54,7 @@ func (this *Redis) MSetNX(keyvalues map[string]interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "MSETNX") for k, v := range keyvalues { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, k, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -121,7 +121,7 @@ Redis Append 命令用于为指定的 key 追加值。 */ func (this *Redis) Append(key string, value interface{}) (err error) { var result []byte - if result, err = this.Encode(value); err == nil { + if result, err = this.encode.Encoder(value); err == nil { err = this.client.Do(this.getContext(), "APPEND", key, result).Err() } return @@ -133,7 +133,7 @@ func (this *Redis) Append(key string, value interface{}) (err error) { func (this *Redis) Get(key string, value interface{}) (err error) { var result []byte if result, err = this.client.Get(this.getContext(), key).Bytes(); err == nil { - err = this.Decode(result, value) + err = this.decode.Decoder(result, value) } return } @@ -146,9 +146,9 @@ func (this *Redis) GetSet(key string, value interface{}, result interface{}) (er data string _value []byte ) - if _value, err = this.Encode(value); err == nil { + if _value, err = this.encode.Encoder(value); err == nil { if data = this.client.Do(this.getContext(), "GETSET", key, _value).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), result) + err = this.decode.Decoder([]byte(data), result) } else { err = fmt.Errorf(string(redis.Nil)) } diff --git a/lego/sys/redis/cluster/zset.go b/lego/sys/redis/cluster/zset.go index 206710e22..0f72b4a9e 100644 --- a/lego/sys/redis/cluster/zset.go +++ b/lego/sys/redis/cluster/zset.go @@ -64,7 +64,7 @@ func (this *Redis) ZRange(valuetype reflect.Type, key string, start int64, stop result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -82,7 +82,7 @@ func (this *Redis) ZRangeByLex(valuetype reflect.Type, key string, opt *redis.ZR result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -100,7 +100,7 @@ func (this *Redis) ZRangeByScore(valuetype reflect.Type, key string, opt *redis. result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -158,7 +158,7 @@ func (this *Redis) ZRevRange(valuetype reflect.Type, key string, start int64, st result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -176,7 +176,7 @@ func (this *Redis) ZRevRangeByScore(valuetype reflect.Type, key string, opt *red result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } diff --git a/lego/sys/redis/core.go b/lego/sys/redis/core.go index 90af5e2c7..f1ef90615 100644 --- a/lego/sys/redis/core.go +++ b/lego/sys/redis/core.go @@ -65,13 +65,13 @@ type ( HDel(key string, fields ...string) (err error) HExists(key string, field string) (result bool, err error) HGet(key string, field string, value interface{}) (err error) - HGetAll(key string, valuetype reflect.Type) (result []interface{}, err error) + HGetAll(key string, v interface{}) (err error) HIncrBy(key string, field string, value int) (err error) HIncrByFloat(key string, field string, value float32) (err error) Hkeys(key string) (result []string, err error) Hlen(key string) (result int, err error) HMGet(key string, valuetype reflect.Type, fields ...string) (result []interface{}, err error) - HMSet(key string, value map[string]interface{}) (err error) + HMSet(key string, v interface{}) (err error) HSet(key string, field string, value interface{}) (err error) HSetNX(key string, field string, value interface{}) (err error) /*Set*/ @@ -115,8 +115,6 @@ type ( ISys interface { IRedis - Encode(value interface{}) (result []byte, err error) - Decode(value []byte, result interface{}) (err error) /*Lock*/ NewRedisMutex(key string, opt ...RMutexOption) (result *RedisMutex, err error) } @@ -155,19 +153,11 @@ func TxPipelined(ctx context.Context, fn func(pipe redis.Pipeliner) error) (err func Watch(ctx context.Context, fn func(*redis.Tx) error, keys ...string) (err error) { return defsys.Watch(ctx, fn) } - -func Encode(value interface{}) (result []byte, err error) { - return defsys.Encode(value) -} -func Decode(value []byte, result interface{}) (err error) { - return defsys.Decode(value, result) -} func Delete(key string) (err error) { return defsys.Delete(key) } func ExistsKey(key string) (iskeep bool, err error) { return defsys.ExistsKey(key) - } func ExpireKey(key string, expire int) (err error) { return defsys.ExpireKey(key, expire) @@ -315,8 +305,8 @@ func HExists(key string, field string) (result bool, err error) { func HGet(key string, field string, value interface{}) (err error) { return defsys.HGet(key, field, value) } -func HGetAll(key string, valuetype reflect.Type) (result []interface{}, err error) { - return defsys.HGetAll(key, valuetype) +func HGetAll(key string, v interface{}) (err error) { + return defsys.HGetAll(key, v) } func HIncrBy(key string, field string, value int) (err error) { return defsys.HIncrBy(key, field, value) @@ -333,8 +323,8 @@ func Hlen(key string) (result int, err error) { func HMGet(key string, valuetype reflect.Type, fields ...string) (result []interface{}, err error) { return defsys.HMGet(key, valuetype, fields...) } -func HMSet(key string, value map[string]interface{}) (err error) { - return defsys.HMSet(key, value) +func HMSet(key string, v interface{}) (err error) { + return defsys.HMSet(key, v) } func HSet(key string, field string, value interface{}) (err error) { return defsys.HSet(key, field, value) diff --git a/lego/sys/redis/redis.go b/lego/sys/redis/redis.go index 82594be04..5e3c50a58 100644 --- a/lego/sys/redis/redis.go +++ b/lego/sys/redis/redis.go @@ -10,6 +10,7 @@ import ( "go_dreamfactory/lego/sys/redis/cluster" "go_dreamfactory/lego/sys/redis/single" + "go_dreamfactory/lego/utils/codec" "github.com/go-redis/redis/v8" "google.golang.org/protobuf/proto" @@ -17,6 +18,13 @@ import ( func newSys(options Options) (sys *Redis, err error) { sys = &Redis{options: options} + if options.RedisStorageType == JsonData { + sys.decoder = &codec.Decoder{DefDecoder: jsoniter.Unmarshal} + sys.encoder = &codec.Encoder{DefEncoder: jsoniter.Marshal} + } else { + sys.decoder = &codec.Decoder{DefDecoder: func(buf []byte, v interface{}) error { return proto.Unmarshal(buf, v.(proto.Message)) }} + sys.encoder = &codec.Encoder{DefEncoder: func(v interface{}) (data []byte, err error) { return proto.Marshal(v.(proto.Message)) }} + } err = sys.init() return } @@ -24,6 +32,8 @@ func newSys(options Options) (sys *Redis, err error) { type Redis struct { options Options client IRedis + decoder codec.IDecoder + encoder codec.IEncoder } func (this *Redis) init() (err error) { @@ -34,16 +44,16 @@ func (this *Redis) init() (err error) { this.options.Redis_Single_DB, this.options.Redis_Single_PoolSize, this.options.TimeOut, - this.Encode, - this.Decode, + this.encoder, + this.decoder, ) } else if this.options.RedisType == Redis_Cluster { this.client, err = cluster.NewSys( this.options.Redis_Cluster_Addr, this.options.Redis_Cluster_Password, this.options.TimeOut, - this.Encode, - this.Decode, + this.encoder, + this.decoder, ) } else { err = fmt.Errorf("init Redis err:RedisType - %d", this.options.RedisType) @@ -73,33 +83,6 @@ func (this *Redis) UnLock(key string) (err error) { return this.client.UnLock(key) } -///数据编码 -func (this *Redis) Encode(value interface{}) (result []byte, err error) { - if this.options.RedisStorageType == JsonData { - result, err = jsoniter.Marshal(value) - } else { - if _, ok := value.(proto.Message); ok { - result, err = proto.Marshal(value.(proto.Message)) - } else { - result, err = jsoniter.Marshal(value) - } - } - return -} - -func (this *Redis) Decode(value []byte, result interface{}) (err error) { - if this.options.RedisStorageType == JsonData { - err = jsoniter.Unmarshal(value, result) - } else { - if _, ok := result.(proto.Message); ok { - err = proto.Unmarshal(value, result.(proto.Message)) - } else { - err = jsoniter.Unmarshal(value, result) - } - } - return -} - func (this *Redis) Delete(key string) (err error) { return this.client.Delete(key) } @@ -242,8 +225,8 @@ func (this *Redis) HExists(key string, field string) (result bool, err error) { func (this *Redis) HGet(key string, field string, value interface{}) (err error) { return this.client.HGet(key, field, value) } -func (this *Redis) HGetAll(key string, valuetype reflect.Type) (result []interface{}, err error) { - return this.client.HGetAll(key, valuetype) +func (this *Redis) HGetAll(key string, v interface{}) (err error) { + return this.client.HGetAll(key, v) } func (this *Redis) HIncrBy(key string, field string, value int) (err error) { return this.client.HIncrBy(key, field, value) @@ -260,8 +243,8 @@ func (this *Redis) Hlen(key string) (result int, err error) { func (this *Redis) HMGet(key string, valuetype reflect.Type, fields ...string) (result []interface{}, err error) { return this.client.HMGet(key, valuetype, fields...) } -func (this *Redis) HMSet(key string, value map[string]interface{}) (err error) { - return this.client.HMSet(key, value) +func (this *Redis) HMSet(key string, v interface{}) (err error) { + return this.client.HMSet(key, v) } func (this *Redis) HSet(key string, field string, value interface{}) (err error) { return this.client.HSet(key, field, value) diff --git a/lego/sys/redis/single/core.go b/lego/sys/redis/single/core.go index 8ea81ce6e..74899c5c1 100644 --- a/lego/sys/redis/single/core.go +++ b/lego/sys/redis/single/core.go @@ -2,14 +2,15 @@ package single import ( "context" + "go_dreamfactory/lego/utils/codec" "time" "github.com/go-redis/redis/v8" ) func NewSys(RedisUrl, RedisPassword string, RedisDB, PoolSize int, timeOut time.Duration, - encode func(value interface{}) (result []byte, err error), - decode func(value []byte, result interface{}) (err error), + encode codec.IEncoder, + decode codec.IDecoder, ) (sys *Redis, err error) { var ( client *redis.Client @@ -23,8 +24,8 @@ func NewSys(RedisUrl, RedisPassword string, RedisDB, PoolSize int, timeOut time. sys = &Redis{ client: client, timeOut: timeOut, - Encode: encode, - Decode: decode, + encode: encode, + decode: decode, } _, err = sys.Ping() return @@ -33,8 +34,8 @@ func NewSys(RedisUrl, RedisPassword string, RedisDB, PoolSize int, timeOut time. type Redis struct { client *redis.Client timeOut time.Duration - Encode func(value interface{}) (result []byte, err error) - Decode func(value []byte, result interface{}) (err error) + encode codec.IEncoder + decode codec.IDecoder } func (this *Redis) getContext() (ctx context.Context) { diff --git a/lego/sys/redis/single/hash.go b/lego/sys/redis/single/hash.go index 91204da1c..80fa9d6b3 100644 --- a/lego/sys/redis/single/hash.go +++ b/lego/sys/redis/single/hash.go @@ -29,13 +29,23 @@ func (this *Redis) HExists(key string, field string) (result bool, err error) { } /* -Redis Hget 命令用于返回哈希表中指定字段的值 +Redis Hmset 命令用于同时将多个 field-value (字段-值)对设置到哈希表中。 +此命令会覆盖哈希表中已存在的字段。 +如果哈希表不存在,会创建一个空哈希表,并执行 HMSET 操作 */ -func (this *Redis) HGet(key string, field string, value interface{}) (err error) { - var resultvalue string - if resultvalue = this.client.Do(this.getContext(), "HSET", key, field).String(); resultvalue != string(redis.Nil) { - err = this.Decode([]byte(resultvalue), value) +func (this *Redis) HMSet(key string, v interface{}) (err error) { + agrs := make([]interface{}, 0) + agrs = append(agrs, "HMSET") + agrs = append(agrs, key) + var data map[string][]byte + if data, err = this.encode.EncoderToMap(v); err != nil { + return } + for k, v := range data { + result, _ := this.encode.Encoder(v) + agrs = append(agrs, k, result) + } + err = this.client.Do(this.getContext(), agrs...).Err() return } @@ -43,18 +53,36 @@ func (this *Redis) HGet(key string, field string, value interface{}) (err error) Redis Hgetall 命令用于返回哈希表中,所有的字段和值。 在返回值里,紧跟每个字段名(field name)之后是字段的值(value),所以返回值的长度是哈希表大小的两倍 */ -func (this *Redis) HGetAll(key string, valuetype reflect.Type) (result []interface{}, err error) { - cmd := redis.NewStringSliceCmd(this.getContext(), "HGETALL", key) +func (this *Redis) HGetAll(key string, v interface{}) (err error) { + cmd := redis.NewStringStringMapCmd(this.getContext(), "HGETALL", key) this.client.Process(this.getContext(), cmd) - var _result []string + var _result map[string]string if _result, err = cmd.Result(); err == nil { - result = make([]interface{}, len(_result)) - for i, v := range _result { - temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { - result[i] = temp - } - } + err = this.decode.DecoderMap(_result, v) + } + return +} + +/* +Redis Hset 命令用于为哈希表中的字段赋值 +如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作 +如果字段已经存在于哈希表中,旧值将被覆盖 +*/ +func (this *Redis) HSet(key string, field string, value interface{}) (err error) { + var resultvalue []byte + if resultvalue, err = this.encode.Encoder(value); err == nil { + err = this.client.Do(this.getContext(), "HSET", key, field, resultvalue).Err() + } + return +} + +/* +Redis Hget 命令用于返回哈希表中指定字段的值 +*/ +func (this *Redis) HGet(key string, field string, value interface{}) (err error) { + var resultvalue string + if resultvalue = this.client.Do(this.getContext(), "HSET", key, field).String(); resultvalue != string(redis.Nil) { + err = this.decode.Decoder([]byte(resultvalue), value) } return } @@ -117,7 +145,7 @@ func (this *Redis) HMGet(key string, valuetype reflect.Type, fields ...string) ( result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -125,36 +153,6 @@ func (this *Redis) HMGet(key string, valuetype reflect.Type, fields ...string) ( return } -/* -Redis Hmset 命令用于同时将多个 field-value (字段-值)对设置到哈希表中。 -此命令会覆盖哈希表中已存在的字段。 -如果哈希表不存在,会创建一个空哈希表,并执行 HMSET 操作 -*/ -func (this *Redis) HMSet(key string, value map[string]interface{}) (err error) { - agrs := make([]interface{}, 0) - agrs = append(agrs, "HMSET") - agrs = append(agrs, key) - for k, v := range value { - result, _ := this.Encode(v) - agrs = append(agrs, k, result) - } - err = this.client.Do(this.getContext(), agrs...).Err() - return -} - -/* -Redis Hset 命令用于为哈希表中的字段赋值 -如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作 -如果字段已经存在于哈希表中,旧值将被覆盖 -*/ -func (this *Redis) HSet(key string, field string, value interface{}) (err error) { - var resultvalue []byte - if resultvalue, err = this.Encode(value); err == nil { - err = this.client.Do(this.getContext(), "HSET", key, field, resultvalue).Err() - } - return -} - /* Redis Hsetnx 命令用于为哈希表中不存在的的字段赋值 如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作 @@ -163,7 +161,7 @@ Redis Hsetnx 命令用于为哈希表中不存在的的字段赋值 */ func (this *Redis) HSetNX(key string, field string, value interface{}) (err error) { var resultvalue []byte - if resultvalue, err = this.Encode(value); err == nil { + if resultvalue, err = this.encode.Encoder(value); err == nil { err = this.client.Do(this.getContext(), "HSETNX", key, field, resultvalue).Err() } return diff --git a/lego/sys/redis/single/list.go b/lego/sys/redis/single/list.go index 18a0011d8..b55e44931 100644 --- a/lego/sys/redis/single/list.go +++ b/lego/sys/redis/single/list.go @@ -13,7 +13,7 @@ Redis Lindex 命令用于通过索引获取列表中的元素。你也可以使 func (this *Redis) Lindex(key string, value interface{}) (err error) { var data string if data = this.client.Do(this.getContext(), "LINDEX", key).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), value) + err = this.decode.Decoder([]byte(data), value) } else { err = fmt.Errorf(string(redis.Nil)) } @@ -30,8 +30,8 @@ func (this *Redis) Linsert(key string, isbefore bool, tager interface{}, value i tagervalue []byte resultvalue []byte ) - if tagervalue, err = this.Encode(tager); err == nil { - if resultvalue, err = this.Encode(value); err == nil { + if tagervalue, err = this.encode.Encoder(tager); err == nil { + if resultvalue, err = this.encode.Encoder(value); err == nil { if isbefore { err = this.client.Do(this.getContext(), "LINSERT", key, "BEFORE", tagervalue, resultvalue).Err() } else { @@ -56,7 +56,7 @@ Redis Lpop 命令用于移除并返回列表的第一个元素 func (this *Redis) LPop(key string, value interface{}) (err error) { var data string if data = this.client.Do(this.getContext(), "LPOP", key).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), value) + err = this.decode.Decoder([]byte(data), value) } else { err = fmt.Errorf(string(redis.Nil)) } @@ -70,7 +70,7 @@ func (this *Redis) LPush(key string, values ...interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "LPUSH") for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -84,7 +84,7 @@ func (this *Redis) LPushX(key string, values ...interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "LPUSHX") for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -103,7 +103,7 @@ func (this *Redis) LRange(key string, start, end int, valuetype reflect.Type) (r result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -120,7 +120,7 @@ count = 0 : 移除表中所有与 VALUE 相等的值 */ func (this *Redis) LRem(key string, count int, target interface{}) (err error) { var resultvalue []byte - if resultvalue, err = this.Encode(target); err == nil { + if resultvalue, err = this.encode.Encoder(target); err == nil { err = this.client.Do(this.getContext(), "LREM", key, count, resultvalue).Err() } return @@ -132,7 +132,7 @@ Redis Lset 通过索引来设置元素的值。 */ func (this *Redis) LSet(key string, index int, value interface{}) (err error) { var resultvalue []byte - if resultvalue, err = this.Encode(value); err == nil { + if resultvalue, err = this.encode.Encoder(value); err == nil { err = this.client.Do(this.getContext(), "LSET", key, index, resultvalue).Err() } return @@ -154,7 +154,7 @@ Redis Rpop 命令用于移除列表的最后一个元素,返回值为移除的 func (this *Redis) Rpop(key string, value interface{}) (err error) { var data string if data = this.client.Do(this.getContext(), "RPOP", key).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), value) + err = this.decode.Decoder([]byte(data), value) } else { err = fmt.Errorf(string(redis.Nil)) } @@ -167,7 +167,7 @@ Redis Rpoplpush 命令用于移除列表的最后一个元素,并将该元素 func (this *Redis) RPopLPush(oldkey string, newkey string, value interface{}) (err error) { var data string if data = this.client.Do(this.getContext(), "RPOPLPUSH", oldkey, newkey).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), value) + err = this.decode.Decoder([]byte(data), value) } else { err = fmt.Errorf(string(redis.Nil)) } @@ -183,7 +183,7 @@ func (this *Redis) RPush(key string, values ...interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "RPUSH") for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -197,7 +197,7 @@ func (this *Redis) RPushX(key string, values ...interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "RPUSHX") for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() diff --git a/lego/sys/redis/single/set.go b/lego/sys/redis/single/set.go index 2e8c86d43..2016c4b2b 100644 --- a/lego/sys/redis/single/set.go +++ b/lego/sys/redis/single/set.go @@ -12,7 +12,7 @@ func (this *Redis) SAdd(key string, values ...interface{}) (err error) { agrs = append(agrs, "SADD") agrs = append(agrs, key) for _, v := range values { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -39,7 +39,7 @@ func (this *Redis) SDiff(valuetype reflect.Type, keys ...string) (result []inter result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -65,7 +65,7 @@ func (this *Redis) SInter(valuetype reflect.Type, keys ...string) (result []inte result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -99,7 +99,7 @@ func (this *Redis) SMembers(valuetype reflect.Type, key string) (result []interf result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -160,7 +160,7 @@ func (this *Redis) SUnion(valuetype reflect.Type, keys ...string) (result []inte result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } diff --git a/lego/sys/redis/single/string.go b/lego/sys/redis/single/string.go index 468d6026b..8c2bbee57 100644 --- a/lego/sys/redis/single/string.go +++ b/lego/sys/redis/single/string.go @@ -13,7 +13,7 @@ import ( */ func (this *Redis) Set(key string, value interface{}, expiration time.Duration) (err error) { var result []byte - if result, err = this.Encode(value); err == nil { + if result, err = this.encode.Encoder(value); err == nil { err = this.client.Set(this.getContext(), string(key), result, expiration).Err() } return @@ -40,7 +40,7 @@ func (this *Redis) MSet(keyvalues map[string]interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "MSET") for k, v := range keyvalues { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, k, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -54,7 +54,7 @@ func (this *Redis) MSetNX(keyvalues map[string]interface{}) (err error) { agrs := make([]interface{}, 0) agrs = append(agrs, "MSETNX") for k, v := range keyvalues { - result, _ := this.Encode(v) + result, _ := this.encode.Encoder(v) agrs = append(agrs, k, result) } err = this.client.Do(this.getContext(), agrs...).Err() @@ -121,7 +121,7 @@ Redis Append 命令用于为指定的 key 追加值。 */ func (this *Redis) Append(key string, value interface{}) (err error) { var result []byte - if result, err = this.Encode(value); err == nil { + if result, err = this.encode.Encoder(value); err == nil { err = this.client.Do(this.getContext(), "APPEND", key, result).Err() } return @@ -133,7 +133,7 @@ func (this *Redis) Append(key string, value interface{}) (err error) { func (this *Redis) Get(key string, value interface{}) (err error) { var result []byte if result, err = this.client.Get(this.getContext(), key).Bytes(); err == nil { - err = this.Decode(result, value) + err = this.decode.Decoder(result, value) } return } @@ -146,9 +146,9 @@ func (this *Redis) GetSet(key string, value interface{}, result interface{}) (er data string _value []byte ) - if _value, err = this.Encode(value); err == nil { + if _value, err = this.encode.Encoder(value); err == nil { if data = this.client.Do(this.getContext(), "GETSET", key, _value).String(); data != string(redis.Nil) { - err = this.Decode([]byte(data), result) + err = this.decode.Decoder([]byte(data), result) } else { err = fmt.Errorf(string(redis.Nil)) } diff --git a/lego/sys/redis/single/zset.go b/lego/sys/redis/single/zset.go index cadf0f13e..0f1015b34 100644 --- a/lego/sys/redis/single/zset.go +++ b/lego/sys/redis/single/zset.go @@ -64,7 +64,7 @@ func (this *Redis) ZRange(valuetype reflect.Type, key string, start int64, stop result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -82,7 +82,7 @@ func (this *Redis) ZRangeByLex(valuetype reflect.Type, key string, opt *redis.ZR result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -100,7 +100,7 @@ func (this *Redis) ZRangeByScore(valuetype reflect.Type, key string, opt *redis. result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -158,7 +158,7 @@ func (this *Redis) ZRevRange(valuetype reflect.Type, key string, start int64, st result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } @@ -176,7 +176,7 @@ func (this *Redis) ZRevRangeByScore(valuetype reflect.Type, key string, opt *red result = make([]interface{}, len(_result)) for i, v := range _result { temp := reflect.New(valuetype.Elem()).Interface() - if err = this.Decode([]byte(v), &temp); err == nil { + if err = this.decode.Decoder([]byte(v), &temp); err == nil { result[i] = temp } } diff --git a/lego/sys/redis/sys_test.go b/lego/sys/redis/sys_test.go index 7d924ce30..ec67d05f5 100644 --- a/lego/sys/redis/sys_test.go +++ b/lego/sys/redis/sys_test.go @@ -3,6 +3,7 @@ package redis_test import ( "encoding/json" "fmt" + "os" "sync" "testing" "time" @@ -10,6 +11,23 @@ import ( "go_dreamfactory/lego/sys/redis" ) +func TestMain(m *testing.M) { + if err := redis.OnInit(nil, + redis.SetRedisType(redis.Redis_Cluster), + redis.SetRedis_Cluster_Addr([]string{"10.0.0.9:9001", "10.0.0.9:9002", "10.0.0.9:9003", "10.0.1.45:9004", "10.0.1.45:9005", "10.0.1.45:9006"}), + redis.SetRedis_Cluster_Password(""), + redis.SetRedisStorageType(redis.JsonData), + ); err != nil { + fmt.Println("err:", err) + return + } + defer os.Exit(m.Run()) + // if err := cache.OnInit(nil, cache.Set_Redis_Addr([]string{"10.0.0.9:9001", "10.0.0.9:9002", "10.0.0.9:9003", "10.0.1.45:9004", "10.0.1.45:9005", "10.0.1.45:9006"}), cache.Set_Redis_Password("")); err != nil { + // fmt.Printf("err:%v\n", err) + // return + // } +} + func Test_SysIPV6(t *testing.T) { err := redis.OnInit(map[string]interface{}{ "Redis_Single_Addr": "172.27.100.143:6382", @@ -139,5 +157,36 @@ func Test_Redis_Type(t *testing.T) { } else { fmt.Printf("Test_Redis_Type:%s \n", ty) } - +} + +type TestData struct { + Name string + Agr int +} + +func Test_Redis_Encoder_Struct(t *testing.T) { + err := redis.Set("test:1001", &TestData{Name: "liwei1dao", Agr: 12}, -1) + fmt.Printf("err:%v\n", err) +} +func Test_Redis_Encoder_int(t *testing.T) { + err := redis.Set("test:1002", 856, -1) + fmt.Printf("err:%v \n", err) + data := 0 + err = redis.Get("test:1002", &data) + fmt.Printf("data:%d err:%v\n", data, err) +} + +func Test_Redis_Encoder_Hash(t *testing.T) { + // err := redis.HMSet("test:1003", &TestData{Name: "liwei1dao", Agr: 12}) + // fmt.Printf("err:%v\n", err) + // data := &TestData{} + // err = redis.HGetAll("test:1003", data) + // fmt.Printf("data:%v err:%v\n", data, err) + + data1 := map[string]*TestData{"li_1": {Name: "liwei2dao", Agr: 56}, "li_2": {Name: "liwei3dao", Agr: 78}} + err := redis.HMSet("test:1004", data1) + fmt.Printf("err:%v\n", err) + data2 := make(map[string]*TestData) + err = redis.HGetAll("test:1004", data2) + fmt.Printf("data2:%v err:%v\n", data2, err) } diff --git a/lego/utils/codec/codec_test.go b/lego/utils/codec/codec_test.go new file mode 100644 index 000000000..4ac021b69 --- /dev/null +++ b/lego/utils/codec/codec_test.go @@ -0,0 +1,29 @@ +package codec + +import ( + "fmt" + "testing" +) + +type TestData struct { + Fild_1 string + Fild_3 int + Fild_4 float32 +} + +func Test_Encoder(t *testing.T) { + encoder := &Encoder{} + // data, err := encoder.EncoderToMap(map[string]interface{}{"liwei": 106, "sasd": "2564"}) + // fmt.Printf("EncoderToMap data1:%v err:%v", data, err) + data, err := encoder.EncoderToMap([]interface{}{"liwei", 106, "sasd", "2564"}) + fmt.Printf("EncoderToMap data1:%v err:%v", data, err) + // data, err := encoder.EncoderToMap(&TestData{Fild_1: "liwei1dao", Fild_3: 25, Fild_4: 3.54}) + // fmt.Printf("EncoderToMap data2:%v err:%v", data, err) +} + +func Test_Decoder(t *testing.T) { + decoder := &Decoder{} + data := &TestData{} + err := decoder.DecoderMap(map[string]string{"Fild_1": "liwei1dao"}, data) + fmt.Printf("DecoderMap data1:%v err:%v", data, err) +} diff --git a/lego/utils/convert/convert.go b/lego/utils/codec/core.go similarity index 70% rename from lego/utils/convert/convert.go rename to lego/utils/codec/core.go index 5a3367a90..a056e153c 100644 --- a/lego/utils/convert/convert.go +++ b/lego/utils/codec/core.go @@ -1,4 +1,4 @@ -package convert +package codec import ( "encoding/binary" @@ -6,68 +6,22 @@ import ( "unsafe" ) -func ByteToBytes(v byte) []byte { - return []byte{v} -} +const host32bit = ^uint(0)>>32 == 0 -func BoolToBytes(v bool) []byte { - var buf = make([]byte, 1) - if v { - buf[0] = 1 - } else { - buf[0] = 0 +type ( + IDecoder interface { + Decoder(buf []byte, v interface{}) error + DecoderMap(data map[string]string, v interface{}) error } - return buf -} -func Int8ToBytes(v int8) []byte { - return []byte{(byte(v))} -} -func Int16ToBytes(v int16) []byte { - var buf = make([]byte, 2) - binary.BigEndian.PutUint16(buf, uint16(v)) - return buf -} -func UInt16ToBytes(v uint16) []byte { - var buf = make([]byte, 2) - binary.BigEndian.PutUint16(buf, v) - return buf -} -func IntToBytes(v int) []byte { - var buf = make([]byte, 4) - binary.BigEndian.PutUint32(buf, uint32(v)) - return buf -} -func Int32ToBytes(v int32) []byte { - var buf = make([]byte, 4) - binary.BigEndian.PutUint32(buf, uint32(v)) - return buf -} -func UInt32ToBytes(v uint32) []byte { - var buf = make([]byte, 4) - binary.BigEndian.PutUint32(buf, v) - return buf -} -func Int64ToBytes(v int64) []byte { - var buf = make([]byte, 8) - binary.BigEndian.PutUint64(buf, uint64(v)) - return buf -} -func UInt64ToBytes(v uint64) []byte { - var buf = make([]byte, 8) - binary.BigEndian.PutUint64(buf, v) - return buf -} -func Float32ToBytes(v float32) []byte { - bits := math.Float32bits(v) - bytes := make([]byte, 4) - binary.LittleEndian.PutUint32(bytes, bits) - return bytes -} -func Float64ToBytes(v float64) []byte { - bits := math.Float64bits(v) - bytes := make([]byte, 8) - binary.LittleEndian.PutUint64(bytes, bits) - return bytes + IEncoder interface { + Encoder(v interface{}) (data []byte, err error) + EncoderToMap(v interface{}) (data map[string][]byte, err error) + } +) + +// string +func BytesToString(b []byte) string { + return *(*string)(unsafe.Pointer(&b)) } func StringToBytes(s string) []byte { return *(*[]byte)(unsafe.Pointer( @@ -78,48 +32,150 @@ func StringToBytes(s string) []byte { )) } -func BytesTobyte(buf []byte) byte { - var data byte = buf[0] - return data +// int +func IntToBytes(v int) []byte { + if host32bit { + return Int32ToBytes(int32(v)) + } else { + return Int64ToBytes(int64(v)) + } } -func BytesToBool(buf []byte) bool { - var data bool = buf[0] != 0 - return data +func BytesToInt(buf []byte) int { + if host32bit { + return int(BytesToInt32(buf)) + } else { + return int(BytesToInt64(buf)) + } +} + +//int8 +func Int8ToBytes(v int8) []byte { + return []byte{(byte(v))} } func BytesToInt8(buf []byte) int8 { - var data int8 = int8(buf[0]) - return data + return int8(buf[0]) +} + +//int16 +func Int16ToBytes(v int16) []byte { + var buf = make([]byte, 2) + binary.BigEndian.PutUint16(buf, uint16(v)) + return buf } func BytesToInt16(buf []byte) int16 { return int16(binary.BigEndian.Uint16(buf)) } -func BytesToUInt16(buf []byte) uint16 { - return binary.BigEndian.Uint16(buf) -} -func BytesToInt(buf []byte) int { - return int(binary.BigEndian.Uint32(buf)) + +//int32 +func Int32ToBytes(v int32) []byte { + var buf = make([]byte, 4) + binary.BigEndian.PutUint32(buf, uint32(v)) + return buf } func BytesToInt32(buf []byte) int32 { return int32(binary.BigEndian.Uint32(buf)) } -func BytesToUInt32(buf []byte) uint32 { - return binary.BigEndian.Uint32(buf) + +//int64 +func Int64ToBytes(v int64) []byte { + var buf = make([]byte, 8) + binary.BigEndian.PutUint64(buf, uint64(v)) + return buf } func BytesToInt64(buf []byte) int64 { return int64(binary.BigEndian.Uint64(buf)) } + +//uint +func UIntToBytes(v uint) []byte { + if host32bit { + return Int32ToBytes(int32(v)) + } else { + return Int64ToBytes(int64(v)) + } +} +func BytesToUInt(buf []byte) uint { + if host32bit { + return uint(BytesToUInt32(buf)) + } else { + return uint(BytesToUInt64(buf)) + } +} + +//uint8 +func UInt8ToBytes(v uint8) []byte { + return []byte{v} +} +func BytesToUInt8(buf []byte) uint8 { + var data uint8 = uint8(buf[0]) + return data +} + +//uint16 +func UInt16ToBytes(v uint16) []byte { + var buf = make([]byte, 2) + binary.BigEndian.PutUint16(buf, v) + return buf +} +func BytesToUInt16(buf []byte) uint16 { + return binary.BigEndian.Uint16(buf) +} + +//uint32 +func UInt32ToBytes(v uint32) []byte { + var buf = make([]byte, 4) + binary.BigEndian.PutUint32(buf, v) + return buf +} +func BytesToUInt32(buf []byte) uint32 { + return binary.BigEndian.Uint32(buf) +} + +//uint64 func BytesToUInt64(buf []byte) uint64 { return binary.BigEndian.Uint64(buf) } +func UInt64ToBytes(v uint64) []byte { + var buf = make([]byte, 8) + binary.BigEndian.PutUint64(buf, v) + return buf +} + +//float32 +func Float32ToBytes(v float32) []byte { + bits := math.Float32bits(v) + bytes := make([]byte, 4) + binary.LittleEndian.PutUint32(bytes, bits) + return bytes +} func BytesToFloat32(buf []byte) float32 { bits := binary.LittleEndian.Uint32(buf) return math.Float32frombits(bits) } + +//float64 +func Float64ToBytes(v float64) []byte { + bits := math.Float64bits(v) + bytes := make([]byte, 8) + binary.LittleEndian.PutUint64(bytes, bits) + return bytes +} func BytesToFloat64(buf []byte) float64 { bits := binary.LittleEndian.Uint64(buf) return math.Float64frombits(bits) } -func BytesToString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) +//bool +func BoolToBytes(v bool) []byte { + var buf = make([]byte, 1) + if v { + buf[0] = 1 + } else { + buf[0] = 0 + } + return buf +} +func BytesToBool(buf []byte) bool { + var data bool = buf[0] != 0 + return data } diff --git a/lego/utils/codec/decoder.go b/lego/utils/codec/decoder.go new file mode 100644 index 000000000..cd3f4c517 --- /dev/null +++ b/lego/utils/codec/decoder.go @@ -0,0 +1,141 @@ +package codec + +import ( + "fmt" + "reflect" + "time" +) + +//解码器 +type Decoder struct { + DefDecoder func(buf []byte, v interface{}) error //默认编码 扩展自定义编码方式 +} + +func (this *Decoder) Decoder(buf []byte, v interface{}) error { + switch v := v.(type) { + case nil: + return fmt.Errorf("decoder: Decoder(nil)") + case *string: + *v = BytesToString(buf) + return nil + case *[]byte: + *v = buf + return nil + case *int: + *v = BytesToInt(buf) + return nil + case *int8: + *v = BytesToInt8(buf) + return nil + case *int16: + *v = BytesToInt16(buf) + return nil + case *int32: + *v = BytesToInt32(buf) + return nil + case *int64: + *v = BytesToInt64(buf) + return nil + case *uint: + *v = BytesToUInt(buf) + return nil + case *uint8: + *v = BytesToUInt8(buf) + return nil + case *uint16: + *v = BytesToUInt16(buf) + return nil + case *uint32: + *v = BytesToUInt32(buf) + return nil + case *uint64: + *v = BytesToUInt64(buf) + return nil + case *float32: + *v = BytesToFloat32(buf) + return nil + case *float64: + *v = BytesToFloat64(buf) + return nil + case *bool: + *v = BytesToBool(buf) + return nil + case *time.Time: + var err error + *v, err = time.Parse(time.RFC3339Nano, BytesToString(buf)) + return err + case *time.Duration: + *v = time.Duration(BytesToInt64(buf)) + return nil + default: + if this.DefDecoder != nil { + return this.DefDecoder(buf, v) + } else { + return fmt.Errorf( + "decoder: can't marshal %T (implement decoder.DefDecoder)", v) + } + } +} + +func (this *Decoder) DecoderMap(data map[string]string, v interface{}) error { + vof := reflect.ValueOf(v) + if !vof.IsValid() { + return fmt.Errorf("Decoder: DecoderMap(nil)") + } + if vof.Kind() != reflect.Ptr && vof.Kind() != reflect.Map && vof.Kind() != reflect.Slice { + return fmt.Errorf("Decoder: DecoderMap(non-pointer %T)", v) + } + if vof.Kind() == reflect.Map { + kt, vt := vof.Type().Key(), vof.Type().Elem() + for k, v := range data { + key := reflect.New(kt).Elem() + if key.Kind() != reflect.Ptr { + if err := this.Decoder(StringToBytes(k), key.Addr().Interface()); err != nil { + return fmt.Errorf("Decoder: Decoder(non-pointer %T) err:%v", key, err) + } + } else { + if err := this.Decoder(StringToBytes(k), key.Addr()); err != nil { + return fmt.Errorf("Decoder: Decoder(non-pointer %T) err:%v", key, err) + } + } + value := reflect.New(vt).Elem() + if value.Kind() != reflect.Ptr { + if err := this.Decoder(StringToBytes(v), value.Addr().Interface()); err != nil { + return fmt.Errorf("Decoder: Decoder(non-pointer %T) err:%v", value, err) + } + } else { + value.Interface() + if err := this.Decoder(StringToBytes(v), value.Addr().Interface()); err != nil { + return fmt.Errorf("Decoder: Decoder(non-pointer %T) err:%v", value, err) + } + } + vof.SetMapIndex(key, value) + } + } else if vof.Kind() == reflect.Ptr { + elem := vof.Elem() + relType := elem.Type() + for i := 0; i < relType.NumField(); i++ { + fieldInfo := relType.Field(i) + tag := fieldInfo.Tag + name := tag.Get("json") + if len(name) == 0 { + name = fieldInfo.Name + } + if value, ok := data[name]; ok { + v := reflect.New(fieldInfo.Type).Elem() + if fieldInfo.Type.Kind() != reflect.Ptr { + if err := this.Decoder(StringToBytes(value), v.Addr().Interface()); err != nil { + return fmt.Errorf("Decoder: Decoder(non-pointer %T) err:%v", value, err) + } + elem.FieldByName(fieldInfo.Name).Set(v) + } else { + if err := this.Decoder(StringToBytes(value), v); err != nil { + return fmt.Errorf("Decoder: Decoder(non-pointer %T) err:%v", value, err) + } + elem.FieldByName(fieldInfo.Name).Set(v) + } + } + } + } + return nil +} diff --git a/lego/utils/codec/encoder.go b/lego/utils/codec/encoder.go new file mode 100644 index 000000000..8de86a4a0 --- /dev/null +++ b/lego/utils/codec/encoder.go @@ -0,0 +1,112 @@ +package codec + +import ( + "fmt" + "reflect" + "time" +) + +//编码器 +type Encoder struct { + DefEncoder func(v interface{}) (data []byte, err error) //默认编码 扩展自定义编码方式 +} + +func (this *Encoder) Encoder(v interface{}) (data []byte, err error) { + switch v := v.(type) { + case nil: + return StringToBytes(""), nil + case string: + return StringToBytes(v), nil + case []byte: + return v, nil + case int: + return IntToBytes(v), nil + case int8: + return Int8ToBytes(v), nil + case int16: + return Int16ToBytes(v), nil + case int32: + return Int32ToBytes(v), nil + case int64: + return Int64ToBytes(v), nil + case uint: + return UIntToBytes(v), nil + case uint8: + return UInt8ToBytes(v), nil + case uint16: + return UInt16ToBytes(v), nil + case uint32: + return UInt32ToBytes(v), nil + case uint64: + return UInt64ToBytes(v), nil + case float32: + return Float32ToBytes(v), nil + case float64: + return Float64ToBytes(v), nil + case bool: + return BoolToBytes(v), nil + case time.Time: + return v.AppendFormat([]byte{}, time.RFC3339Nano), nil + case time.Duration: + return Int64ToBytes(v.Nanoseconds()), nil + default: + if this.DefEncoder != nil { + return this.DefEncoder(v) + } else { + return nil, fmt.Errorf( + "encoder: can't marshal %T (implement encoder.DefEncoder)", v) + } + } +} + +func (this *Encoder) EncoderToMap(v interface{}) (data map[string][]byte, err error) { + vof := reflect.ValueOf(v) + if !vof.IsValid() { + return nil, fmt.Errorf("Encoder: EncoderToMap(nil)") + } + if vof.Kind() != reflect.Ptr && vof.Kind() != reflect.Map && vof.Kind() != reflect.Slice { + return nil, fmt.Errorf("Encoder: EncoderToMap(non-pointer %T)", v) + } + // vof = vof.Elem() + data = make(map[string][]byte) + if vof.Kind() == reflect.Map { + keys := vof.MapKeys() + for _, k := range keys { + value := vof.MapIndex(k) + var keydata []byte + var valuedata []byte + if keydata, err = this.Encoder(k.Interface()); err != nil { + return nil, fmt.Errorf("Encoder: EncoderToMap(invalid type %T) err:%v", value.Interface(), err) + } + if valuedata, err = this.Encoder(value.Interface()); err != nil { + return nil, fmt.Errorf("Encoder: EncoderToMap(invalid type %T) err:%v", value.Interface(), err) + } + data[BytesToString(keydata)] = valuedata + } + return + } else if vof.Kind() == reflect.Slice { + for i := 0; i < vof.Len(); i++ { + value := vof.Index(i).Interface() + var valuedata []byte + if valuedata, err = this.Encoder(value); err != nil { + return nil, fmt.Errorf("Encoder: EncoderToMap(invalid type %T) err:%v", value, err) + } + data[BytesToString(IntToBytes(i))] = valuedata + } + return + } else if vof.Kind() == reflect.Ptr { + elem := vof.Elem() + relType := elem.Type() + for i := 0; i < relType.NumField(); i++ { + field := elem.Field(i).Interface() + var valuedata []byte + if valuedata, err = this.Encoder(field); err != nil { + return nil, fmt.Errorf("Encoder: EncoderToMap(invalid type %T) err:%v", field, err) + } + data[relType.Field(i).Name] = valuedata + } + return + } else { + return nil, fmt.Errorf("Encoder: EncoderToMap(invalid type %T)", v) + } +} diff --git a/modules/core.go b/modules/core.go index d8a7d5da0..8123a7a6c 100644 --- a/modules/core.go +++ b/modules/core.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/pb" "github.com/golang/protobuf/proto" + "go.mongodb.org/mongo-driver/bson" ) type ( @@ -26,7 +27,7 @@ type ( // 向db 写日志信息 InsertModelLogs(table string, uID string, target interface{}) (err error) DeleteModelLogs(table string, uID string, where interface{}) (err error) - UpdateModelLogs(table string, uID string, where interface{}, target interface{}) (err error) + UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error) } IDB_Comp interface { } diff --git a/modules/dbservice/core.go b/modules/dbservice/core.go index f4b9d8432..6c7345fa7 100644 --- a/modules/dbservice/core.go +++ b/modules/dbservice/core.go @@ -2,8 +2,6 @@ package dbservice import ( "go_dreamfactory/lego/core" - - "go.mongodb.org/mongo-driver/bson" ) const ( @@ -16,11 +14,6 @@ var ( ErrorLogCount = make(map[string]uint32, 0) ) -type QueryStruct struct { - Selector bson.M - Query bson.M -} - const ( DB_ModelTable core.SqlTable = "model_log" ) diff --git a/modules/dbservice/db_comp.go b/modules/dbservice/db_comp.go index eab23f4cc..adf78f107 100644 --- a/modules/dbservice/db_comp.go +++ b/modules/dbservice/db_comp.go @@ -89,7 +89,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { log.Errorf("insert db err max num %s db err:%v", data.ID, err) _, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID}) if err != nil { - log.Errorf("insert %s db err:%v", data.ID, err) + log.Errorf("insert %s db err:%+v", data.ID, err) } } continue @@ -116,7 +116,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { log.Errorf("del db err max num %s db err:%v", data.ID, err) _, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID}) if err != nil { - log.Errorf("insert %s db err:%v", data.ID, err) + log.Errorf("insert %s db err:%+v", data.ID, err) } } continue @@ -126,20 +126,19 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { log.Errorf("parameter len _id : %s,uid : %s d.len:%v", data.ID, data.UID, len(data.D)) continue } + _key := data.D[0].(string) - where := data.D[1].(bson.D) - _obj := &QueryStruct{ - Selector: make(map[string]interface{}), - Query: make(map[string]interface{}), + Where := make(bson.M, 0) + Query := make(bson.M, 0) + Query1 := make(bson.M, 0) + Query1["$set"] = Query + for _, v := range data.D[1].(bson.D) { + Where[v.Key] = v } - for _, v := range where { - _obj.Selector[v.Key] = v + for _, v := range data.D[2].(bson.D) { + Query[v.Key] = v } - query := data.D[2].(bson.D) - for _, v := range query { - _obj.Query[v.Key] = v - } - _, err := this.DB.UpdateMany(core.SqlTable(_key), _obj.Selector, _obj.Query) + _, err := this.DB.UpdateMany(core.SqlTable(_key), Where, Query1) if err != nil { log.Errorf("Update %s db err:%v", core.SqlTable(_key), err) ErrorLogCount[data.ID]++ @@ -147,7 +146,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { log.Errorf("update db err max num %s db err:%v", data.ID, err) _, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID}) if err != nil { - log.Errorf("insert %s db err:%v", data.ID, err) + log.Errorf("insert %s db err:%+v", data.ID, err) } } continue diff --git a/modules/dbservice/mail_test.go b/modules/dbservice/mail_test.go deleted file mode 100644 index 7a7377708..000000000 --- a/modules/dbservice/mail_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package dbservice - -import ( - "go_dreamfactory/pb" - "os" - "testing" - "time" - - "go.mongodb.org/mongo-driver/bson/primitive" -) - -var module = new(DBService) - -func TestMain(m *testing.M) { - for i := 0; i < 50000; i++ { - //go func() { - _mail := &pb.DB_MailData{ - ObjId: primitive.NewObjectID().Hex(), - UserId: "uid123", - Title: "系统邮件", - - Contex: "恭喜获得专属礼包一份", - CreateTime: uint64(time.Now().Unix()), - DueTime: uint64(time.Now().Unix()) + 30*24*3600, - Check: false, - Reward: false, - } - module.db_comp.InsertModelLogs("mail", "uid123", _mail) - //db.InsertModelLogs("mail", "uid123", _mail) - //InsertModelLogs("mail", "uid123", _mail) - // data := &comm.Autogenerated{ - // ID: primitive.NewObjectID().Hex(), - // UID: "uid123", - // Act: string(comm.LogHandleType_Insert), - // } - // data.D = append(data.D, "mail") // D[0] - // data.D = append(data.D, _mail) // D[1] - - // _, err1 := module.db_comp.DB.InsertOne("model_log", data) - // if err1 != nil { - // log.Errorf("insert model db err %v", err1) - // } - //}() - } - time.Sleep(time.Second * 10) - defer os.Exit(m.Run()) -} diff --git a/modules/gate_comp.go b/modules/gate_comp.go index 69526fafd..89ba53cf0 100644 --- a/modules/gate_comp.go +++ b/modules/gate_comp.go @@ -21,6 +21,7 @@ import ( // var typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem() var typeOfSession = reflect.TypeOf((*comm.IUserSession)(nil)).Elem() var typeOfMapStringIntface = reflect.TypeOf((map[string]interface{})(nil)).Elem() +var typeOfCode = reflect.TypeOf((*comm.ErrorCode)(nil)).Elem() var typeOfErrorCode = reflect.TypeOf((*pb.ErrorCode)(nil)).Elem() var typeOfError = reflect.TypeOf((*error)(nil)).Elem() @@ -96,7 +97,8 @@ func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) { if mtype.NumOut() != 1 { return } - if returnType := mtype.Out(0); returnType != typeOfError { + returnCodeType := mtype.Out(0) + if returnCodeType != typeOfErrorCode { return } this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), replyType, method) @@ -134,7 +136,7 @@ func (this *MComp_GateComp) reflectionRouteCheck(method reflect.Method) { return } returnCodeType := mtype.Out(1) - if returnCodeType != typeOfErrorCode { + if returnCodeType != typeOfCode { return } this.scomp.RegisterRouteCheck(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname[0])), reflect.ValueOf(this.comp), replyType, method) diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index ec8bdd84f..09863dfb2 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -11,6 +11,7 @@ import ( "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/utils/container/id" + "github.com/golang/protobuf/ptypes" "github.com/gorilla/websocket" "google.golang.org/protobuf/proto" ) @@ -154,7 +155,14 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) { Message: msg.Data, }, reply); err != nil { log.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err) - } else { - log.Debugf("agent:%s uId:%s MessageDistribution reply:%v", this.sessionId, this.uId, reply) + return + } + if reply.Code != pb.ErrorCode_Success { + data, _ := ptypes.MarshalAny(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: reply.Code}) + this.WriteMsg(&pb.UserMessage{ + MainType: "notify", + SubType: "errornotify", + Data: data, + }) } } diff --git a/modules/gateway/agentmgr_comp.go b/modules/gateway/agentmgr_comp.go index 52dfcc523..e69b3f7b1 100644 --- a/modules/gateway/agentmgr_comp.go +++ b/modules/gateway/agentmgr_comp.go @@ -39,7 +39,7 @@ func (this *AgentMgr_Comp) Bind(ctx context.Context, args *pb.AgentBuildReq, rep a.(IAgent).Bind(args.UserId, args.WorkerId) } else { reply.Code = pb.ErrorCode_UserSessionNobeing - reply.Msg = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) + reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) } return nil } @@ -50,7 +50,7 @@ func (this *AgentMgr_Comp) UnBind(ctx context.Context, args *pb.AgentUnBuildReq, a.(IAgent).UnBind() } else { reply.Code = pb.ErrorCode_UserSessionNobeing - reply.Msg = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) + reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) } return nil } @@ -61,12 +61,11 @@ func (this *AgentMgr_Comp) SendMsgToAgent(ctx context.Context, args *pb.AgentSen a.(IAgent).WriteMsg(&pb.UserMessage{ MainType: args.MainType, SubType: args.SubType, - Code: args.Code, Data: args.Data, }) } else { reply.Code = pb.ErrorCode_UserSessionNobeing - reply.Msg = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) + reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) } return nil } @@ -106,7 +105,7 @@ func (this *AgentMgr_Comp) CloseAgent(ctx context.Context, args *pb.AgentCloseeR a.(IAgent).Close() } else { reply.Code = pb.ErrorCode_UserSessionNobeing - reply.Msg = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) + reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing) } return nil } diff --git a/modules/mail/api_delmail.go b/modules/mail/api_delmail.go index 4437de43f..28197ee7b 100644 --- a/modules/mail/api_delmail.go +++ b/modules/mail/api_delmail.go @@ -12,12 +12,11 @@ func (this *Api_Comp) DelUserMailReq_Check(session comm.IUserSession, req *pb.De } // 删除邮件 -func (this *Api_Comp) DelUserMailReq(session comm.IUserSession, agrs map[string]interface{}, req *pb.DelUserMailReq) (err error) { - - code := pb.ErrorCode_Success +func (this *Api_Comp) DelUserMailReq(session comm.IUserSession, agrs map[string]interface{}, req *pb.DelUserMailReq) (code pb.ErrorCode) { + var err error mailinfo := make([]*pb.DB_MailData, 0) defer func() { - session.SendMsg(string(this.module.GetType()), DelUserMailResp, code, &pb.DelUserMailResp{Mail: mailinfo}) + session.SendMsg(string(this.module.GetType()), DelUserMailResp, &pb.DelUserMailResp{Mail: mailinfo}) }() if session.GetUserId() == "" { code = pb.ErrorCode_NoLogin diff --git a/modules/mail/api_getAttachment.go b/modules/mail/api_getAttachment.go index dda538725..5fb73e0ee 100644 --- a/modules/mail/api_getAttachment.go +++ b/modules/mail/api_getAttachment.go @@ -5,19 +5,18 @@ import ( "go_dreamfactory/pb" ) -func (this *Api_Comp) GetUserMailAttachmentReq_Check(session comm.IUserSession, req *pb.GetUserMailAttachmentReq) (result map[string]interface{}, code pb.ErrorCode) { +func (this *Api_Comp) GetUserMailAttachmentReq_Check(session comm.IUserSession, req *pb.GetUserMailAttachmentReq) (result map[string]interface{}, code comm.ErrorCode) { return } // 领取附件 -func (this *Api_Comp) GetUserMailAttachmentReq(session comm.IUserSession, agrs map[string]interface{}, req *pb.GetUserMailAttachmentReq) (err error) { +func (this *Api_Comp) GetUserMailAttachmentReq(session comm.IUserSession, agrs map[string]interface{}, req *pb.GetUserMailAttachmentReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode mail *pb.DB_MailData ) defer func() { - session.SendMsg(string(this.module.GetType()), GetUserMailAttachmentResp, code, &pb.GetUserMailAttachmentResp{Mail: mail}) + session.SendMsg(string(this.module.GetType()), GetUserMailAttachmentResp, &pb.GetUserMailAttachmentResp{Mail: mail}) }() if session.GetUserId() == "" { code = pb.ErrorCode_NoLogin diff --git a/modules/mail/api_getmail.go b/modules/mail/api_getmail.go index a582681c3..fd8bc4350 100644 --- a/modules/mail/api_getmail.go +++ b/modules/mail/api_getmail.go @@ -6,17 +6,17 @@ import ( "go_dreamfactory/pb" ) -func (this *Api_Comp) QueryUserMailReq_Check(session comm.IUserSession, req *pb.QueryUserMailReq) (result map[string]interface{}, code pb.ErrorCode) { +func (this *Api_Comp) QueryUserMailReq_Check(session comm.IUserSession, req *pb.QueryUserMailReq) (result map[string]interface{}, code comm.ErrorCode) { return } // 查看所有邮件信息 -func (this *Api_Comp) QueryUserMailReq(session comm.IUserSession, agrs map[string]interface{}, req *pb.QueryUserMailReq) (err error) { +func (this *Api_Comp) QueryUserMailReq(session comm.IUserSession, agrs map[string]interface{}, req *pb.QueryUserMailReq) (code pb.ErrorCode) { - code := pb.ErrorCode_Success + var err error mailinfo := make([]*pb.DB_MailData, 0) defer func() { - session.SendMsg(string(this.module.GetType()), QueryUserMailResp, code, &pb.QueryUserMailResp{Mails: mailinfo}) + session.SendMsg(string(this.module.GetType()), QueryUserMailResp, &pb.QueryUserMailResp{Mails: mailinfo}) }() if session.GetUserId() == "" { code = pb.ErrorCode_NoLogin diff --git a/modules/mail/api_readmail.go b/modules/mail/api_readmail.go index 9b8574cde..33321ceb2 100644 --- a/modules/mail/api_readmail.go +++ b/modules/mail/api_readmail.go @@ -5,18 +5,18 @@ import ( "go_dreamfactory/pb" ) -func (this *Api_Comp) ReadUserMailReq_Check(session comm.IUserSession, req *pb.ReadUserMailReq) (result map[string]interface{}, code pb.ErrorCode) { +func (this *Api_Comp) ReadUserMailReq_Check(session comm.IUserSession, req *pb.ReadUserMailReq) (result map[string]interface{}, code comm.ErrorCode) { return } // 查看某一封邮件 -func (this *Api_Comp) ReadUserMailReq(session comm.IUserSession, agrs map[string]interface{}, req *pb.ReadUserMailReq) (err error) { +func (this *Api_Comp) ReadUserMailReq(session comm.IUserSession, agrs map[string]interface{}, req *pb.ReadUserMailReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode + err error mail *pb.DB_MailData ) defer func() { - session.SendMsg(string(this.module.GetType()), ReadUserMailResp, code, &pb.ReadUserMailResp{Mail: mail}) + session.SendMsg(string(this.module.GetType()), ReadUserMailResp, &pb.ReadUserMailResp{Mail: mail}) }() if session.GetUserId() == "" { code = pb.ErrorCode_NoLogin diff --git a/modules/model_comp.go b/modules/model_comp.go index 3bda04061..7f62917df 100644 --- a/modules/model_comp.go +++ b/modules/model_comp.go @@ -79,7 +79,7 @@ func (this *Model_Comp) DeleteModelLogs(table string, uID string, where interfac return err } -func (this *Model_Comp) UpdateModelLogs(table string, uID string, where interface{}, target interface{}) (err error) { +func (this *Model_Comp) UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error) { data := &comm.Autogenerated{ ID: primitive.NewObjectID().Hex(), diff --git a/modules/pack/api_getlist.go b/modules/pack/api_getlist.go index 16ce99fec..8285f391e 100644 --- a/modules/pack/api_getlist.go +++ b/modules/pack/api_getlist.go @@ -8,15 +8,15 @@ import ( ) //参数校验 -func (this *Api_Comp) Getlist_Check(session comm.IUserSession, req *pb.GetlistReq) (result map[string]interface{}, code pb.ErrorCode) { +func (this *Api_Comp) Getlist_Check(session comm.IUserSession, req *pb.GetlistReq) (result map[string]interface{}, code comm.ErrorCode) { result = map[string]interface{}{"ce": 123} return } ///获取用户道具 -func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.GetlistReq) (err error) { +func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.GetlistReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode + err error items []*pb.DB_UserItemData nt int64 tempgrids []*pb.DB_UserItemData @@ -25,7 +25,7 @@ func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interfa dels []string ) defer func() { - session.SendMsg(string(this.module.GetType()), GetlistResp, code, &pb.GetlistResp{Grids: grids}) + session.SendMsg(string(this.module.GetType()), GetlistResp, &pb.GetlistResp{Grids: grids}) if code == pb.ErrorCode_Success { go func() { //异步处理修改数据 this.module.cache_comp.Pack_UpdateUserPack(session.GetUserId(), modifys...) diff --git a/modules/pack/api_sellItem.go b/modules/pack/api_sellItem.go index b5ddf36ea..8dbc6d389 100644 --- a/modules/pack/api_sellItem.go +++ b/modules/pack/api_sellItem.go @@ -6,18 +6,15 @@ import ( ) //参数校验 -func (this *Api_Comp) SellItem_Check(session comm.IUserSession, req *pb.SellItemReq) (result map[string]interface{}, code pb.ErrorCode) { +func (this *Api_Comp) SellItem_Check(session comm.IUserSession, req *pb.SellItemReq) (result map[string]interface{}, code comm.ErrorCode) { return } //出售道具 -func (this *Api_Comp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.SellItemReq) (err error) { - var ( - code pb.ErrorCode - ) +func (this *Api_Comp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.SellItemReq) (code pb.ErrorCode) { defer func() { - session.SendMsg(string(this.module.GetType()), SellItemResp, code, &pb.SellItemResp{}) + session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.SellItemResp{}) }() return } diff --git a/modules/pack/api_useItem.go b/modules/pack/api_useItem.go index ce6302207..37b14fce1 100644 --- a/modules/pack/api_useItem.go +++ b/modules/pack/api_useItem.go @@ -6,18 +6,15 @@ import ( ) //参数校验 -func (this *Api_Comp) Useitem_Check(session comm.IUserSession, req *pb.UseItemReq) (result map[string]interface{}, code pb.ErrorCode) { +func (this *Api_Comp) Useitem_Check(session comm.IUserSession, req *pb.UseItemReq) (result map[string]interface{}, code comm.ErrorCode) { return } //使用道具 -func (this *Api_Comp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.UseItemReq) (err error) { - var ( - code pb.ErrorCode - ) +func (this *Api_Comp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.UseItemReq) (code pb.ErrorCode) { defer func() { - session.SendMsg(string(this.module.GetType()), UseItemResp, code, &pb.UseItemResp{}) + session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.UseItemResp{}) }() return diff --git a/modules/pack/cache_comp.go b/modules/pack/cache_comp.go index 6a60f2db3..f775b1080 100644 --- a/modules/pack/cache_comp.go +++ b/modules/pack/cache_comp.go @@ -7,7 +7,6 @@ import ( "go_dreamfactory/lego/sys/redis" "go_dreamfactory/modules" "go_dreamfactory/pb" - "reflect" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -27,27 +26,27 @@ func (this *Cache_Comp) Init(service core.IService, module core.IModule, comp co ///查询用户背包数据 func (this *Cache_Comp) Pack_QueryUserPack(uId string) (itmes []*pb.DB_UserItemData, err error) { - var ( - lists []interface{} - temp map[string]interface{} - ) - if lists, err = this.Redis.HGetAll(fmt.Sprintf(Redis_PackCache, uId), reflect.TypeOf(pb.DB_UserItemData{})); err == nil { - itmes = make([]*pb.DB_UserItemData, 0, len(lists)) - for i, v := range lists { - itmes[i] = v.(*pb.DB_UserItemData) - } - return - } else if err == redis.RedisNil { - if itmes, err = this.module.db_comp.Pack_QueryUserPack(uId); err == nil { - temp = make(map[string]interface{}) - for _, v := range itmes { - temp[v.GridId] = v - } - this.Redis.HMSet(fmt.Sprintf(Redis_PackCache, uId), temp) - } else if err == mgo.MongodbNil { - err = nil - } - } + // var ( + // lists []interface{} + // temp map[string]interface{} + // ) + // if lists, err = this.Redis.HGetAll(fmt.Sprintf(Redis_PackCache, uId), reflect.TypeOf(pb.DB_UserItemData{})); err == nil { + // itmes = make([]*pb.DB_UserItemData, 0, len(lists)) + // for i, v := range lists { + // itmes[i] = v.(*pb.DB_UserItemData) + // } + // return + // } else if err == redis.RedisNil { + // if itmes, err = this.module.db_comp.Pack_QueryUserPack(uId); err == nil { + // temp = make(map[string]interface{}) + // for _, v := range itmes { + // temp[v.GridId] = v + // } + // this.Redis.HMSet(fmt.Sprintf(Redis_PackCache, uId), temp) + // } else if err == mgo.MongodbNil { + // err = nil + // } + // } return } diff --git a/pb.bat b/pb.bat index 44f2fa5bc..59ab0d057 100644 --- a/pb.bat +++ b/pb.bat @@ -8,6 +8,7 @@ set SRC=%PROJECT_ROOT%\pb\proto set TAR=%PROJECT_ROOT%\pb protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\*.proto +protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\notify\*.proto protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\user\*.proto protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\friend\*.proto protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\pack\*.proto diff --git a/pb/comm.pb.go b/pb/comm.pb.go index dbf65b8ff..7cd18c8e1 100644 --- a/pb/comm.pb.go +++ b/pb/comm.pb.go @@ -27,10 +27,9 @@ type UserMessage struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType"` - SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType"` - Code ErrorCode `protobuf:"varint,3,opt,name=Code,proto3,enum=ErrorCode" json:"Code"` - Data *anypb.Any `protobuf:"bytes,4,opt,name=data,proto3" json:"data"` + MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType,omitempty"` //用户消息处理 模块名 例如:user 对应项目中 user的模块 + SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType,omitempty"` //用户消息处理函数名 例如:login 对应项目中 user的模块中 api_login 的处理函数 + Data *anypb.Any `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` } func (x *UserMessage) Reset() { @@ -79,13 +78,6 @@ func (x *UserMessage) GetSubType() string { return "" } -func (x *UserMessage) GetCode() ErrorCode { - if x != nil { - return x.Code - } - return ErrorCode_Success -} - func (x *UserMessage) GetData() *anypb.Any { if x != nil { return x.Data @@ -99,12 +91,12 @@ type AgentMessage struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Ip string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip"` - UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId"` - UserId string `protobuf:"bytes,3,opt,name=UserId,proto3" json:"UserId"` - GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"` - Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method"` - Message *anypb.Any `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message"` + Ip string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip,omitempty"` + UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` + UserId string `protobuf:"bytes,3,opt,name=UserId,proto3" json:"UserId,omitempty"` + GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"` + Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method,omitempty"` + Message *anypb.Any `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message,omitempty"` } func (x *AgentMessage) Reset() { @@ -187,8 +179,9 @@ type RPCMessageReply struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"` - Msg string `protobuf:"bytes,2,opt,name=Msg,proto3" json:"Msg"` + Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"` + Message string `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message,omitempty"` + Data string `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"` } func (x *RPCMessageReply) Reset() { @@ -230,9 +223,16 @@ func (x *RPCMessageReply) GetCode() ErrorCode { return ErrorCode_Success } -func (x *RPCMessageReply) GetMsg() string { +func (x *RPCMessageReply) GetMessage() string { if x != nil { - return x.Msg + return x.Message + } + return "" +} + +func (x *RPCMessageReply) GetData() string { + if x != nil { + return x.Data } return "" } @@ -243,9 +243,9 @@ type AgentBuildReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId"` - UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId"` - WorkerId string `protobuf:"bytes,3,opt,name=WorkerId,proto3" json:"WorkerId"` + UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId,omitempty"` + WorkerId string `protobuf:"bytes,3,opt,name=WorkerId,proto3" json:"WorkerId,omitempty"` } func (x *AgentBuildReq) Reset() { @@ -307,7 +307,7 @@ type AgentUnBuildReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId"` + UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` } func (x *AgentUnBuildReq) Reset() { @@ -355,11 +355,10 @@ type AgentSendMessageReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId"` - MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType"` - SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType"` - Code ErrorCode `protobuf:"varint,4,opt,name=Code,proto3,enum=ErrorCode" json:"Code"` - Data *anypb.Any `protobuf:"bytes,5,opt,name=Data,proto3" json:"Data"` + UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` + MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType,omitempty"` + SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType,omitempty"` + Data *anypb.Any `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data,omitempty"` } func (x *AgentSendMessageReq) Reset() { @@ -415,13 +414,6 @@ func (x *AgentSendMessageReq) GetSubType() string { return "" } -func (x *AgentSendMessageReq) GetCode() ErrorCode { - if x != nil { - return x.Code - } - return ErrorCode_Success -} - func (x *AgentSendMessageReq) GetData() *anypb.Any { if x != nil { return x.Data @@ -435,10 +427,10 @@ type BatchMessageReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserSessionIds []string `protobuf:"bytes,1,rep,name=UserSessionIds,proto3" json:"UserSessionIds"` - MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType"` - SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType"` - Data *anypb.Any `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data"` + UserSessionIds []string `protobuf:"bytes,1,rep,name=UserSessionIds,proto3" json:"UserSessionIds,omitempty"` + MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType,omitempty"` + SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType,omitempty"` + Data *anypb.Any `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data,omitempty"` } func (x *BatchMessageReq) Reset() { @@ -507,9 +499,9 @@ type BroadCastMessageReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType"` //服务名 - SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType"` - Data *anypb.Any `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data"` + MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType,omitempty"` //服务名 + SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType,omitempty"` + Data *anypb.Any `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"` } func (x *BroadCastMessageReq) Reset() { @@ -571,7 +563,7 @@ type AgentCloseeReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId"` + UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"` } func (x *AgentCloseeReq) Reset() { @@ -619,77 +611,75 @@ var file_comm_proto_rawDesc = []byte{ 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, - 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8d, 0x01, 0x0a, 0x0b, 0x55, 0x73, 0x65, - 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, - 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, - 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, - 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, - 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x28, - 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, - 0x6e, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xd0, 0x01, 0x0a, 0x0c, 0x41, 0x67, 0x65, - 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, - 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, - 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, - 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x2e, 0x0a, 0x07, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, - 0x6e, 0x79, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x43, 0x0a, 0x0f, 0x52, - 0x50, 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1e, - 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, - 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x10, - 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, - 0x22, 0x69, 0x0a, 0x0d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, - 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, - 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, - 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, - 0x1a, 0x0a, 0x08, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x22, 0x37, 0x0a, 0x0f, 0x41, - 0x67, 0x65, 0x6e, 0x74, 0x55, 0x6e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, - 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, - 0x6f, 0x6e, 0x49, 0x64, 0x22, 0xbb, 0x01, 0x0a, 0x13, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x53, 0x65, - 0x6e, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, + 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6d, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, + 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, + 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xd0, 0x01, 0x0a, 0x0c, 0x41, 0x67, 0x65, 0x6e, + 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, + 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, + 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x2e, 0x0a, 0x07, 0x4d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, + 0x79, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x5f, 0x0a, 0x0f, 0x52, 0x50, + 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1e, 0x0a, + 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, + 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, + 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x69, 0x0a, 0x0d, 0x41, + 0x67, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, - 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, - 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, - 0x74, 0x61, 0x22, 0x99, 0x01, 0x0a, 0x0f, 0x42, 0x61, 0x74, 0x63, 0x68, 0x4d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, - 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, - 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x12, 0x1a, - 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, - 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, - 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x75, - 0x0a, 0x13, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, - 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, - 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, - 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x43, 0x6c, - 0x6f, 0x73, 0x65, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, + 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x57, 0x6f, + 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x57, 0x6f, + 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x22, 0x37, 0x0a, 0x0f, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x55, + 0x6e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, + 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, + 0x9b, 0x01, 0x0a, 0x13, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, - 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, + 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x99, 0x01, + 0x0a, 0x0f, 0x42, 0x61, 0x74, 0x63, 0x68, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, + 0x71, 0x12, 0x26, 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x49, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, + 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, + 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, + 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x75, 0x0a, 0x13, 0x42, 0x72, 0x6f, + 0x61, 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, + 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, + 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, + 0x22, 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x65, 0x52, + 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, + 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -715,23 +705,21 @@ var file_comm_proto_goTypes = []interface{}{ (*BatchMessageReq)(nil), // 6: BatchMessageReq (*BroadCastMessageReq)(nil), // 7: BroadCastMessageReq (*AgentCloseeReq)(nil), // 8: AgentCloseeReq - (ErrorCode)(0), // 9: ErrorCode - (*anypb.Any)(nil), // 10: google.protobuf.Any + (*anypb.Any)(nil), // 9: google.protobuf.Any + (ErrorCode)(0), // 10: ErrorCode } var file_comm_proto_depIdxs = []int32{ - 9, // 0: UserMessage.Code:type_name -> ErrorCode - 10, // 1: UserMessage.data:type_name -> google.protobuf.Any - 10, // 2: AgentMessage.Message:type_name -> google.protobuf.Any - 9, // 3: RPCMessageReply.Code:type_name -> ErrorCode - 9, // 4: AgentSendMessageReq.Code:type_name -> ErrorCode - 10, // 5: AgentSendMessageReq.Data:type_name -> google.protobuf.Any - 10, // 6: BatchMessageReq.Data:type_name -> google.protobuf.Any - 10, // 7: BroadCastMessageReq.Data:type_name -> google.protobuf.Any - 8, // [8:8] is the sub-list for method output_type - 8, // [8:8] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 9, // 0: UserMessage.data:type_name -> google.protobuf.Any + 9, // 1: AgentMessage.Message:type_name -> google.protobuf.Any + 10, // 2: RPCMessageReply.Code:type_name -> ErrorCode + 9, // 3: AgentSendMessageReq.Data:type_name -> google.protobuf.Any + 9, // 4: BatchMessageReq.Data:type_name -> google.protobuf.Any + 9, // 5: BroadCastMessageReq.Data:type_name -> google.protobuf.Any + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_comm_proto_init() } diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index 3a3ec720f..ab36879cd 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -25,17 +25,18 @@ type ErrorCode int32 const ( ErrorCode_Success ErrorCode = 0 //成功 ErrorCode_NoFindService ErrorCode = 10 //没有找到远程服务器 - ErrorCode_RpcFuncExecutionError ErrorCode = 11 //Rpc方法执行错误 - ErrorCode_CacheReadError ErrorCode = 12 //缓存读取失败 - ErrorCode_SqlExecutionError ErrorCode = 13 //数据库执行错误 - ErrorCode_ReqParameterError ErrorCode = 14 //请求参数错误 - ErrorCode_SignError ErrorCode = 15 //签名错误 - ErrorCode_InsufficientPermissions ErrorCode = 16 //权限不足 - ErrorCode_NoLogin ErrorCode = 17 //未登录 - ErrorCode_UserSessionNobeing ErrorCode = 18 //用户不存在 - ErrorCode_StateInvalid ErrorCode = 21 //无效状态 - ErrorCode_DBError ErrorCode = 22 // 数据库操作失败 - ErrorCode_SystemError ErrorCode = 23 // 通用错误 + ErrorCode_NoFindServiceHandleFunc ErrorCode = 11 //远程服务器未找到执行方法 + ErrorCode_RpcFuncExecutionError ErrorCode = 12 //Rpc方法执行错误 + ErrorCode_CacheReadError ErrorCode = 13 //缓存读取失败 + ErrorCode_SqlExecutionError ErrorCode = 14 //数据库执行错误 + ErrorCode_ReqParameterError ErrorCode = 15 //请求参数错误 + ErrorCode_SignError ErrorCode = 16 //签名错误 + ErrorCode_InsufficientPermissions ErrorCode = 17 //权限不足 + ErrorCode_NoLogin ErrorCode = 18 //未登录 + ErrorCode_UserSessionNobeing ErrorCode = 19 //用户不存在 + ErrorCode_StateInvalid ErrorCode = 20 //无效状态 + ErrorCode_DBError ErrorCode = 21 // 数据库操作失败 + ErrorCode_SystemError ErrorCode = 22 // 通用错误 //user ErrorCode_SecKeyInvalid ErrorCode = 1000 //秘钥无效 ErrorCode_SecKey ErrorCode = 1001 //秘钥格式错误 @@ -58,17 +59,18 @@ var ( ErrorCode_name = map[int32]string{ 0: "Success", 10: "NoFindService", - 11: "RpcFuncExecutionError", - 12: "CacheReadError", - 13: "SqlExecutionError", - 14: "ReqParameterError", - 15: "SignError", - 16: "InsufficientPermissions", - 17: "NoLogin", - 18: "UserSessionNobeing", - 21: "StateInvalid", - 22: "DBError", - 23: "SystemError", + 11: "NoFindServiceHandleFunc", + 12: "RpcFuncExecutionError", + 13: "CacheReadError", + 14: "SqlExecutionError", + 15: "ReqParameterError", + 16: "SignError", + 17: "InsufficientPermissions", + 18: "NoLogin", + 19: "UserSessionNobeing", + 20: "StateInvalid", + 21: "DBError", + 22: "SystemError", 1000: "SecKeyInvalid", 1001: "SecKey", 1100: "FriendNotSelf", @@ -86,17 +88,18 @@ var ( ErrorCode_value = map[string]int32{ "Success": 0, "NoFindService": 10, - "RpcFuncExecutionError": 11, - "CacheReadError": 12, - "SqlExecutionError": 13, - "ReqParameterError": 14, - "SignError": 15, - "InsufficientPermissions": 16, - "NoLogin": 17, - "UserSessionNobeing": 18, - "StateInvalid": 21, - "DBError": 22, - "SystemError": 23, + "NoFindServiceHandleFunc": 11, + "RpcFuncExecutionError": 12, + "CacheReadError": 13, + "SqlExecutionError": 14, + "ReqParameterError": 15, + "SignError": 16, + "InsufficientPermissions": 17, + "NoLogin": 18, + "UserSessionNobeing": 19, + "StateInvalid": 20, + "DBError": 21, + "SystemError": 22, "SecKeyInvalid": 1000, "SecKey": 1001, "FriendNotSelf": 1100, @@ -144,42 +147,43 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2a, 0x9d, 0x04, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0xba, 0x04, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, - 0x19, 0x0a, 0x15, 0x52, 0x70, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, - 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0b, 0x12, 0x12, 0x0a, 0x0e, 0x43, 0x61, - 0x63, 0x68, 0x65, 0x52, 0x65, 0x61, 0x64, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0c, 0x12, 0x15, - 0x0a, 0x11, 0x53, 0x71, 0x6c, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x72, - 0x72, 0x6f, 0x72, 0x10, 0x0d, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x65, 0x71, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x65, 0x74, 0x65, 0x72, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0e, 0x12, 0x0d, 0x0a, 0x09, - 0x53, 0x69, 0x67, 0x6e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0f, 0x12, 0x1b, 0x0a, 0x17, 0x49, - 0x6e, 0x73, 0x75, 0x66, 0x66, 0x69, 0x63, 0x69, 0x65, 0x6e, 0x74, 0x50, 0x65, 0x72, 0x6d, 0x69, - 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x10, 0x10, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x6f, 0x4c, 0x6f, - 0x67, 0x69, 0x6e, 0x10, 0x11, 0x12, 0x16, 0x0a, 0x12, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x4e, 0x6f, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x10, 0x12, 0x12, 0x10, 0x0a, - 0x0c, 0x53, 0x74, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x15, 0x12, - 0x0b, 0x0a, 0x07, 0x44, 0x42, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x16, 0x12, 0x0f, 0x0a, 0x0b, - 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x17, 0x12, 0x12, 0x0a, - 0x0d, 0x53, 0x65, 0x63, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0xe8, - 0x07, 0x12, 0x0b, 0x0a, 0x06, 0x53, 0x65, 0x63, 0x4b, 0x65, 0x79, 0x10, 0xe9, 0x07, 0x12, 0x12, - 0x0a, 0x0d, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x4e, 0x6f, 0x74, 0x53, 0x65, 0x6c, 0x66, 0x10, - 0xcc, 0x08, 0x12, 0x12, 0x0a, 0x0d, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, - 0x4d, 0x61, 0x78, 0x10, 0xcd, 0x08, 0x12, 0x14, 0x0a, 0x0f, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, - 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x4d, 0x61, 0x78, 0x10, 0xce, 0x08, 0x12, 0x15, 0x0a, 0x10, - 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, 0x4e, 0x6f, 0x44, 0x61, 0x74, 0x61, - 0x10, 0xcf, 0x08, 0x12, 0x17, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, - 0x67, 0x65, 0x74, 0x4e, 0x6f, 0x44, 0x61, 0x74, 0x61, 0x10, 0xd0, 0x08, 0x12, 0x0e, 0x0a, 0x09, - 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x59, 0x65, 0x74, 0x10, 0xd1, 0x08, 0x12, 0x13, 0x0a, 0x0e, - 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x59, 0x65, 0x74, 0x10, 0xd2, - 0x08, 0x12, 0x17, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, 0x42, - 0x6c, 0x61, 0x63, 0x6b, 0x59, 0x65, 0x74, 0x10, 0xd3, 0x08, 0x12, 0x19, 0x0a, 0x14, 0x46, 0x72, - 0x69, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x59, - 0x65, 0x74, 0x10, 0xd4, 0x08, 0x12, 0x15, 0x0a, 0x10, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, - 0x70, 0x70, 0x6c, 0x79, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0xd5, 0x08, 0x12, 0x13, 0x0a, 0x0e, - 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x4d, 0x61, 0x78, 0x10, 0xd6, - 0x08, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x46, 0x75, 0x6e, 0x63, 0x10, 0x0b, 0x12, 0x19, 0x0a, 0x15, + 0x52, 0x70, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, + 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0c, 0x12, 0x12, 0x0a, 0x0e, 0x43, 0x61, 0x63, 0x68, 0x65, + 0x52, 0x65, 0x61, 0x64, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0d, 0x12, 0x15, 0x0a, 0x11, 0x53, + 0x71, 0x6c, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x6f, 0x72, + 0x10, 0x0e, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x65, 0x71, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, + 0x65, 0x72, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x0f, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x69, 0x67, + 0x6e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x10, 0x12, 0x1b, 0x0a, 0x17, 0x49, 0x6e, 0x73, 0x75, + 0x66, 0x66, 0x69, 0x63, 0x69, 0x65, 0x6e, 0x74, 0x50, 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, + 0x6f, 0x6e, 0x73, 0x10, 0x11, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x6f, 0x4c, 0x6f, 0x67, 0x69, 0x6e, + 0x10, 0x12, 0x12, 0x16, 0x0a, 0x12, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x4e, 0x6f, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x10, 0x13, 0x12, 0x10, 0x0a, 0x0c, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x14, 0x12, 0x0b, 0x0a, 0x07, + 0x44, 0x42, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x15, 0x12, 0x0f, 0x0a, 0x0b, 0x53, 0x79, 0x73, + 0x74, 0x65, 0x6d, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x16, 0x12, 0x12, 0x0a, 0x0d, 0x53, 0x65, + 0x63, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0xe8, 0x07, 0x12, 0x0b, + 0x0a, 0x06, 0x53, 0x65, 0x63, 0x4b, 0x65, 0x79, 0x10, 0xe9, 0x07, 0x12, 0x12, 0x0a, 0x0d, 0x46, + 0x72, 0x69, 0x65, 0x6e, 0x64, 0x4e, 0x6f, 0x74, 0x53, 0x65, 0x6c, 0x66, 0x10, 0xcc, 0x08, 0x12, + 0x12, 0x0a, 0x0d, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, 0x4d, 0x61, 0x78, + 0x10, 0xcd, 0x08, 0x12, 0x14, 0x0a, 0x0f, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x4d, 0x61, 0x78, 0x10, 0xce, 0x08, 0x12, 0x15, 0x0a, 0x10, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, 0x4e, 0x6f, 0x44, 0x61, 0x74, 0x61, 0x10, 0xcf, 0x08, + 0x12, 0x17, 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, + 0x4e, 0x6f, 0x44, 0x61, 0x74, 0x61, 0x10, 0xd0, 0x08, 0x12, 0x0e, 0x0a, 0x09, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x59, 0x65, 0x74, 0x10, 0xd1, 0x08, 0x12, 0x13, 0x0a, 0x0e, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x59, 0x65, 0x74, 0x10, 0xd2, 0x08, 0x12, 0x17, + 0x0a, 0x12, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x53, 0x65, 0x6c, 0x66, 0x42, 0x6c, 0x61, 0x63, + 0x6b, 0x59, 0x65, 0x74, 0x10, 0xd3, 0x08, 0x12, 0x19, 0x0a, 0x14, 0x46, 0x72, 0x69, 0x65, 0x6e, + 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x59, 0x65, 0x74, 0x10, + 0xd4, 0x08, 0x12, 0x15, 0x0a, 0x10, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x70, 0x70, 0x6c, + 0x79, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0xd5, 0x08, 0x12, 0x13, 0x0a, 0x0e, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x4d, 0x61, 0x78, 0x10, 0xd6, 0x08, 0x42, 0x06, + 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/friend_db.pb.go b/pb/friend_db.pb.go index b2fc9e3b8..c5a69f3cd 100644 --- a/pb/friend_db.pb.go +++ b/pb/friend_db.pb.go @@ -25,10 +25,10 @@ type DB_FriendData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId" bson:"_id"` // ID - FriendIds []string `protobuf:"bytes,2,rep,name=friendIds,proto3" json:"friendIds"` //好友ID - ApplyIds []string `protobuf:"bytes,3,rep,name=applyIds,proto3" json:"applyIds"` //申请用户ID - BlackIds []string `protobuf:"bytes,4,rep,name=blackIds,proto3" json:"blackIds"` //黑名单ID + UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty" bson:"_id"` // ID + FriendIds []string `protobuf:"bytes,2,rep,name=friendIds,proto3" json:"friendIds,omitempty"` //好友ID + ApplyIds []string `protobuf:"bytes,3,rep,name=applyIds,proto3" json:"applyIds,omitempty"` //申请用户ID + BlackIds []string `protobuf:"bytes,4,rep,name=blackIds,proto3" json:"blackIds,omitempty"` //黑名单ID } func (x *DB_FriendData) Reset() { diff --git a/pb/friend_msg.pb.go b/pb/friend_msg.pb.go index 4885e5909..725a918e5 100644 --- a/pb/friend_msg.pb.go +++ b/pb/friend_msg.pb.go @@ -25,13 +25,13 @@ type FriendBase struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId"` //ID - NickName string `protobuf:"bytes,2,opt,name=NickName,proto3" json:"NickName"` //昵称 - Level int32 `protobuf:"varint,3,opt,name=level,proto3" json:"level"` //等级 - Avatar int32 `protobuf:"varint,4,opt,name=avatar,proto3" json:"avatar"` //头像 - Strength int64 `protobuf:"varint,5,opt,name=strength,proto3" json:"strength"` //战力 - ServerId int32 `protobuf:"varint,6,opt,name=serverId,proto3" json:"serverId"` //服务编号 - OfflineTime int64 `protobuf:"varint,7,opt,name=offlineTime,proto3" json:"offlineTime"` //最近一次下线时间 0在线 + UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty"` //ID + NickName string `protobuf:"bytes,2,opt,name=NickName,proto3" json:"NickName,omitempty"` //昵称 + Level int32 `protobuf:"varint,3,opt,name=level,proto3" json:"level,omitempty"` //等级 + Avatar int32 `protobuf:"varint,4,opt,name=avatar,proto3" json:"avatar,omitempty"` //头像 + Strength int64 `protobuf:"varint,5,opt,name=strength,proto3" json:"strength,omitempty"` //战力 + ServerId int32 `protobuf:"varint,6,opt,name=serverId,proto3" json:"serverId,omitempty"` //服务编号 + OfflineTime int64 `protobuf:"varint,7,opt,name=offlineTime,proto3" json:"offlineTime,omitempty"` //最近一次下线时间 0在线 } func (x *FriendBase) Reset() { @@ -159,7 +159,7 @@ type FriendListRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list"` + List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` } func (x *FriendListRsp) Reset() { @@ -207,7 +207,7 @@ type FriendApplyReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` //好友ID + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID } func (x *FriendApplyReq) Reset() { @@ -254,8 +254,8 @@ type FriendApplyRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId"` //用户ID - FriendId string `protobuf:"bytes,2,opt,name=friendId,proto3" json:"friendId"` //好友ID + UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty"` //用户ID + FriendId string `protobuf:"bytes,2,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID } func (x *FriendApplyRsp) Reset() { @@ -310,7 +310,7 @@ type FriendDelReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` //好友ID + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID } func (x *FriendDelReq) Reset() { @@ -357,8 +357,8 @@ type FriendDelRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` //好友ID - UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"` //用户ID + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID + UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` //用户ID } func (x *FriendDelRsp) Reset() { @@ -413,7 +413,7 @@ type FriendAgreeReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendIds []string `protobuf:"bytes,1,rep,name=friendIds,proto3" json:"friendIds"` //被同意的用户 + FriendIds []string `protobuf:"bytes,1,rep,name=friendIds,proto3" json:"friendIds,omitempty"` //被同意的用户 } func (x *FriendAgreeReq) Reset() { @@ -460,7 +460,7 @@ type FriendAgreeRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Num int32 `protobuf:"varint,1,opt,name=Num,proto3" json:"Num"` //操作的数量 + Num int32 `protobuf:"varint,1,opt,name=Num,proto3" json:"Num,omitempty"` //操作的数量 } func (x *FriendAgreeRsp) Reset() { @@ -508,7 +508,7 @@ type FriendRefuseReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendIds []string `protobuf:"bytes,1,rep,name=friendIds,proto3" json:"friendIds"` //被拒绝的用户 + FriendIds []string `protobuf:"bytes,1,rep,name=friendIds,proto3" json:"friendIds,omitempty"` //被拒绝的用户 } func (x *FriendRefuseReq) Reset() { @@ -555,7 +555,7 @@ type FriendRefuseRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Num int32 `protobuf:"varint,1,opt,name=Num,proto3" json:"Num"` //操作的数量 + Num int32 `protobuf:"varint,1,opt,name=Num,proto3" json:"Num,omitempty"` //操作的数量 } func (x *FriendRefuseRsp) Reset() { @@ -641,7 +641,7 @@ type FriendApplyListRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list"` + List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` } func (x *FriendApplyListRsp) Reset() { @@ -689,7 +689,7 @@ type FriendSearchReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - NickName string `protobuf:"bytes,1,opt,name=nickName,proto3" json:"nickName"` //好友昵称 + NickName string `protobuf:"bytes,1,opt,name=nickName,proto3" json:"nickName,omitempty"` //好友昵称 } func (x *FriendSearchReq) Reset() { @@ -736,7 +736,7 @@ type FriendSearchRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Friend *FriendBase `protobuf:"bytes,1,opt,name=friend,proto3" json:"friend"` + Friend *FriendBase `protobuf:"bytes,1,opt,name=friend,proto3" json:"friend,omitempty"` } func (x *FriendSearchRsp) Reset() { @@ -822,7 +822,7 @@ type FriendBlackListRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Friends []*FriendBase `protobuf:"bytes,1,rep,name=friends,proto3" json:"friends"` + Friends []*FriendBase `protobuf:"bytes,1,rep,name=friends,proto3" json:"friends,omitempty"` } func (x *FriendBlackListRsp) Reset() { @@ -870,7 +870,7 @@ type FriendBlackAddReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` } func (x *FriendBlackAddReq) Reset() { @@ -917,8 +917,8 @@ type FriendBlackAddRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` - UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` } func (x *FriendBlackAddRsp) Reset() { @@ -973,7 +973,7 @@ type FriendDelBlackReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` } func (x *FriendDelBlackReq) Reset() { @@ -1020,8 +1020,8 @@ type FriendDelBlackRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` - UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` } func (x *FriendDelBlackRsp) Reset() { @@ -1076,7 +1076,7 @@ type FriendReceiveReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` } func (x *FriendReceiveReq) Reset() { @@ -1123,8 +1123,8 @@ type FriendReceiveRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` - UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` } func (x *FriendReceiveRsp) Reset() { @@ -1179,7 +1179,7 @@ type FriendGiveReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` } func (x *FriendGiveReq) Reset() { @@ -1226,8 +1226,8 @@ type FriendGiveRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` - UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` } func (x *FriendGiveRsp) Reset() { @@ -1282,7 +1282,7 @@ type FriendTotalReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` } func (x *FriendTotalReq) Reset() { @@ -1329,8 +1329,8 @@ type FriendTotalRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` - Total int32 `protobuf:"varint,2,opt,name=total,proto3" json:"total"` //好友数量 + FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` + Total int32 `protobuf:"varint,2,opt,name=total,proto3" json:"total,omitempty"` //好友数量 } func (x *FriendTotalRsp) Reset() { diff --git a/pb/mail_db.pb.go b/pb/mail_db.pb.go index 29cd81e91..c4a422a41 100644 --- a/pb/mail_db.pb.go +++ b/pb/mail_db.pb.go @@ -25,8 +25,8 @@ type MailAttachment struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ItemId uint32 `protobuf:"varint,1,opt,name=ItemId,proto3" json:"ItemId"` // 道具iD - ItemCount uint32 `protobuf:"varint,2,opt,name=ItemCount,proto3" json:"ItemCount"` // 数量 + ItemId uint32 `protobuf:"varint,1,opt,name=ItemId,proto3" json:"ItemId,omitempty"` // 道具iD + ItemCount uint32 `protobuf:"varint,2,opt,name=ItemCount,proto3" json:"ItemCount,omitempty"` // 数量 } func (x *MailAttachment) Reset() { @@ -80,15 +80,15 @@ type DB_MailData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ObjId string `protobuf:"bytes,1,opt,name=ObjId,proto3" json:"ObjId" bson:"_id"` // ID - UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId"` - Title string `protobuf:"bytes,3,opt,name=Title,proto3" json:"Title"` // 邮件标题 - Contex string `protobuf:"bytes,4,opt,name=Contex,proto3" json:"Contex"` // 邮件内容 - CreateTime uint64 `protobuf:"varint,5,opt,name=CreateTime,proto3" json:"CreateTime"` // 发送时间 - DueTime uint64 `protobuf:"varint,6,opt,name=DueTime,proto3" json:"DueTime"` // 过期时间 - Check bool `protobuf:"varint,7,opt,name=Check,proto3" json:"Check"` // 是否查看 - Reward bool `protobuf:"varint,8,opt,name=Reward,proto3" json:"Reward"` // 附件领取状态 - Items []*MailAttachment `protobuf:"bytes,9,rep,name=Items,proto3" json:"Items"` // 附件 + ObjId string `protobuf:"bytes,1,opt,name=ObjId,proto3" json:"ObjId,omitempty" bson:"_id"` // ID + UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId,omitempty"` + Title string `protobuf:"bytes,3,opt,name=Title,proto3" json:"Title,omitempty"` // 邮件标题 + Contex string `protobuf:"bytes,4,opt,name=Contex,proto3" json:"Contex,omitempty"` // 邮件内容 + CreateTime uint64 `protobuf:"varint,5,opt,name=CreateTime,proto3" json:"CreateTime,omitempty"` // 发送时间 + DueTime uint64 `protobuf:"varint,6,opt,name=DueTime,proto3" json:"DueTime,omitempty"` // 过期时间 + Check bool `protobuf:"varint,7,opt,name=Check,proto3" json:"Check,omitempty"` // 是否查看 + Reward bool `protobuf:"varint,8,opt,name=Reward,proto3" json:"Reward,omitempty"` // 附件领取状态 + Items []*MailAttachment `protobuf:"bytes,9,rep,name=Items,proto3" json:"Items,omitempty"` // 附件 } func (x *DB_MailData) Reset() { diff --git a/pb/mail_msg.pb.go b/pb/mail_msg.pb.go index ba6149350..388595803 100644 --- a/pb/mail_msg.pb.go +++ b/pb/mail_msg.pb.go @@ -64,7 +64,7 @@ type QueryUserMailResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Mails []*DB_MailData `protobuf:"bytes,1,rep,name=Mails,proto3" json:"Mails"` + Mails []*DB_MailData `protobuf:"bytes,1,rep,name=Mails,proto3" json:"Mails,omitempty"` } func (x *QueryUserMailResp) Reset() { @@ -112,7 +112,7 @@ type ReadUserMailReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID"` + ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID,omitempty"` } func (x *ReadUserMailReq) Reset() { @@ -159,7 +159,7 @@ type ReadUserMailResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Mail *DB_MailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail"` + Mail *DB_MailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail,omitempty"` } func (x *ReadUserMailResp) Reset() { @@ -207,7 +207,7 @@ type GetUserMailAttachmentReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID"` + ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID,omitempty"` } func (x *GetUserMailAttachmentReq) Reset() { @@ -254,7 +254,7 @@ type GetUserMailAttachmentResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Mail *DB_MailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail"` + Mail *DB_MailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail,omitempty"` } func (x *GetUserMailAttachmentResp) Reset() { @@ -302,7 +302,7 @@ type DelUserMailReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID"` + ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID,omitempty"` } func (x *DelUserMailReq) Reset() { @@ -349,7 +349,7 @@ type DelUserMailResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Mail []*DB_MailData `protobuf:"bytes,1,rep,name=Mail,proto3" json:"Mail"` + Mail []*DB_MailData `protobuf:"bytes,1,rep,name=Mail,proto3" json:"Mail,omitempty"` } func (x *DelUserMailResp) Reset() { diff --git a/pb/notify_msg.pb.go b/pb/notify_msg.pb.go new file mode 100644 index 000000000..a1a995cf5 --- /dev/null +++ b/pb/notify_msg.pb.go @@ -0,0 +1,186 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: notify/notify_msg.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +//统一错误码返回 +type ErrorNotify struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ReqMainType string `protobuf:"bytes,1,opt,name=ReqMainType,proto3" json:"ReqMainType,omitempty"` // 请求协议模块 模块名 例如:user 对应项目中 user的模块 + ReqSubType string `protobuf:"bytes,2,opt,name=ReqSubType,proto3" json:"ReqSubType,omitempty"` // 请求协议函数 例如:login 对应项目中 user的模块中 api_login 的处理函数 + Code ErrorCode `protobuf:"varint,3,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"` // 执行返回错误码 对应 errorcode.proto 枚举 + Message string `protobuf:"bytes,4,opt,name=Message,proto3" json:"Message,omitempty"` // 错误消息 + Data string `protobuf:"bytes,6,opt,name=Data,proto3" json:"Data,omitempty"` // 错误数据 +} + +func (x *ErrorNotify) Reset() { + *x = ErrorNotify{} + if protoimpl.UnsafeEnabled { + mi := &file_notify_notify_msg_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ErrorNotify) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ErrorNotify) ProtoMessage() {} + +func (x *ErrorNotify) ProtoReflect() protoreflect.Message { + mi := &file_notify_notify_msg_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 ErrorNotify.ProtoReflect.Descriptor instead. +func (*ErrorNotify) Descriptor() ([]byte, []int) { + return file_notify_notify_msg_proto_rawDescGZIP(), []int{0} +} + +func (x *ErrorNotify) GetReqMainType() string { + if x != nil { + return x.ReqMainType + } + return "" +} + +func (x *ErrorNotify) GetReqSubType() string { + if x != nil { + return x.ReqSubType + } + return "" +} + +func (x *ErrorNotify) GetCode() ErrorCode { + if x != nil { + return x.Code + } + return ErrorCode_Success +} + +func (x *ErrorNotify) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *ErrorNotify) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +var File_notify_notify_msg_proto protoreflect.FileDescriptor + +var file_notify_notify_msg_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x2f, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x5f, + 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9d, 0x01, 0x0a, 0x0b, 0x45, + 0x72, 0x72, 0x6f, 0x72, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x52, 0x65, + 0x71, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x52, 0x65, 0x71, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, + 0x52, 0x65, 0x71, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x52, 0x65, 0x71, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04, + 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, + 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, + 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_notify_notify_msg_proto_rawDescOnce sync.Once + file_notify_notify_msg_proto_rawDescData = file_notify_notify_msg_proto_rawDesc +) + +func file_notify_notify_msg_proto_rawDescGZIP() []byte { + file_notify_notify_msg_proto_rawDescOnce.Do(func() { + file_notify_notify_msg_proto_rawDescData = protoimpl.X.CompressGZIP(file_notify_notify_msg_proto_rawDescData) + }) + return file_notify_notify_msg_proto_rawDescData +} + +var file_notify_notify_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_notify_notify_msg_proto_goTypes = []interface{}{ + (*ErrorNotify)(nil), // 0: ErrorNotify + (ErrorCode)(0), // 1: ErrorCode +} +var file_notify_notify_msg_proto_depIdxs = []int32{ + 1, // 0: ErrorNotify.Code:type_name -> ErrorCode + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] 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_notify_notify_msg_proto_init() } +func file_notify_notify_msg_proto_init() { + if File_notify_notify_msg_proto != nil { + return + } + file_errorcode_proto_init() + if !protoimpl.UnsafeEnabled { + file_notify_notify_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ErrorNotify); 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_notify_notify_msg_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_notify_notify_msg_proto_goTypes, + DependencyIndexes: file_notify_notify_msg_proto_depIdxs, + MessageInfos: file_notify_notify_msg_proto_msgTypes, + }.Build() + File_notify_notify_msg_proto = out.File + file_notify_notify_msg_proto_rawDesc = nil + file_notify_notify_msg_proto_goTypes = nil + file_notify_notify_msg_proto_depIdxs = nil +} diff --git a/pb/pack_db.pb.go b/pb/pack_db.pb.go index b353fea0f..235c28ad7 100644 --- a/pb/pack_db.pb.go +++ b/pb/pack_db.pb.go @@ -26,14 +26,14 @@ type DB_UserItemData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - GridId string `protobuf:"bytes,1,opt,name=GridId,proto3" json:"GridId"` //背包格子Id - UId string `protobuf:"bytes,2,opt,name=UId,proto3" json:"UId"` //用户id - IsEmpty bool `protobuf:"varint,3,opt,name=IsEmpty,proto3" json:"IsEmpty"` //是否是空格子 - ItemId int32 `protobuf:"varint,4,opt,name=ItemId,proto3" json:"ItemId"` //存放物品的Id - Amount uint32 `protobuf:"varint,5,opt,name=Amount,proto3" json:"Amount"` //存放物品的数量 - CTime int64 `protobuf:"varint,6,opt,name=CTime,proto3" json:"CTime"` //物品获取时间 - ETime int64 `protobuf:"varint,7,opt,name=ETime,proto3" json:"ETime"` //物品过期时间 - IsNewItem bool `protobuf:"varint,8,opt,name=IsNewItem,proto3" json:"IsNewItem"` //是否是新的 + GridId string `protobuf:"bytes,1,opt,name=GridId,proto3" json:"GridId,omitempty"` //背包格子Id + UId string `protobuf:"bytes,2,opt,name=UId,proto3" json:"UId,omitempty"` //用户id + IsEmpty bool `protobuf:"varint,3,opt,name=IsEmpty,proto3" json:"IsEmpty,omitempty"` //是否是空格子 + ItemId int32 `protobuf:"varint,4,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //存放物品的Id + Amount uint32 `protobuf:"varint,5,opt,name=Amount,proto3" json:"Amount,omitempty"` //存放物品的数量 + CTime int64 `protobuf:"varint,6,opt,name=CTime,proto3" json:"CTime,omitempty"` //物品获取时间 + ETime int64 `protobuf:"varint,7,opt,name=ETime,proto3" json:"ETime,omitempty"` //物品过期时间 + IsNewItem bool `protobuf:"varint,8,opt,name=IsNewItem,proto3" json:"IsNewItem,omitempty"` //是否是新的 } func (x *DB_UserItemData) Reset() { diff --git a/pb/pack_msg.pb.go b/pb/pack_msg.pb.go index 140b19eeb..ca8145d3d 100644 --- a/pb/pack_msg.pb.go +++ b/pb/pack_msg.pb.go @@ -26,7 +26,7 @@ type GetlistReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - IType int32 `protobuf:"varint,1,opt,name=IType,proto3" json:"IType"` //道具类型 + IType int32 `protobuf:"varint,1,opt,name=IType,proto3" json:"IType,omitempty"` //道具类型 } func (x *GetlistReq) Reset() { @@ -74,7 +74,7 @@ type GetlistResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Grids []*DB_UserItemData `protobuf:"bytes,1,rep,name=Grids,proto3" json:"Grids"` //用户背包列表 + Grids []*DB_UserItemData `protobuf:"bytes,1,rep,name=Grids,proto3" json:"Grids,omitempty"` //用户背包列表 } func (x *GetlistResp) Reset() { @@ -122,9 +122,9 @@ type UseItemReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - GridId int32 `protobuf:"varint,1,opt,name=GridId,proto3" json:"GridId"` //格子Id - ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId"` //物品Id - Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount"` //使用数量 + GridId int32 `protobuf:"varint,1,opt,name=GridId,proto3" json:"GridId,omitempty"` //格子Id + ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //物品Id + Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount,omitempty"` //使用数量 } func (x *UseItemReq) Reset() { @@ -225,9 +225,9 @@ type SellItemReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - GridId int32 `protobuf:"varint,1,opt,name=GridId,proto3" json:"GridId"` //格子Id - ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId"` //物品Id - Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount"` //使用数量 + GridId int32 `protobuf:"varint,1,opt,name=GridId,proto3" json:"GridId,omitempty"` //格子Id + ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //物品Id + Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount,omitempty"` //使用数量 } func (x *SellItemReq) Reset() { diff --git a/pb/proto/comm.proto b/pb/proto/comm.proto index 0066cdd98..ca1921372 100644 --- a/pb/proto/comm.proto +++ b/pb/proto/comm.proto @@ -5,10 +5,9 @@ import "google/protobuf/any.proto"; //用户消息流结构 message UserMessage { - string MainType =1; - string SubType = 2; - ErrorCode Code = 3; - google.protobuf.Any data = 4; + string MainType =1; //用户消息处理 模块名 例如:user 对应项目中 user的模块 + string SubType = 2; //用户消息处理函数名 例如:login 对应项目中 user的模块中 api_login 的处理函数 + google.protobuf.Any data = 3; } //代理用户转发消息结构 @@ -24,7 +23,8 @@ message AgentMessage { //RPC 服务固定回复结构 message RPCMessageReply { ErrorCode Code = 1; - string Msg = 2; + string Message = 2; + string Data = 3; } //用户代理绑定Uid请求 @@ -43,8 +43,7 @@ message AgentSendMessageReq { string UserSessionId = 1; string MainType = 2; string SubType = 3; - ErrorCode Code = 4; - google.protobuf.Any Data = 5; + google.protobuf.Any Data = 4; } //发送批量消息 diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto index d095cd53d..406585345 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -5,17 +5,18 @@ option go_package = ".;pb"; enum ErrorCode { Success = 0; //成功 NoFindService = 10; //没有找到远程服务器 - RpcFuncExecutionError = 11; //Rpc方法执行错误 - CacheReadError = 12; //缓存读取失败 - SqlExecutionError = 13; //数据库执行错误 - ReqParameterError = 14; //请求参数错误 - SignError = 15; //签名错误 - InsufficientPermissions = 16; //权限不足 - NoLogin = 17; //未登录 - UserSessionNobeing = 18; //用户不存在 - StateInvalid = 21; //无效状态 - DBError = 22; // 数据库操作失败 - SystemError = 23; // 通用错误 + NoFindServiceHandleFunc = 11; //远程服务器未找到执行方法 + RpcFuncExecutionError = 12; //Rpc方法执行错误 + CacheReadError = 13; //缓存读取失败 + SqlExecutionError = 14; //数据库执行错误 + ReqParameterError = 15; //请求参数错误 + SignError = 16; //签名错误 + InsufficientPermissions = 17; //权限不足 + NoLogin = 18; //未登录 + UserSessionNobeing = 19; //用户不存在 + StateInvalid = 20; //无效状态 + DBError = 21; // 数据库操作失败 + SystemError = 22; // 通用错误 //user SecKeyInvalid = 1000; //秘钥无效 diff --git a/pb/proto/notify/notify_msg.proto b/pb/proto/notify/notify_msg.proto new file mode 100644 index 000000000..fdd30f7d0 --- /dev/null +++ b/pb/proto/notify/notify_msg.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +option go_package = ".;pb"; +import "errorcode.proto"; + +//统一错误码返回 +message ErrorNotify { + string ReqMainType =1; // 请求协议模块 模块名 例如:user 对应项目中 user的模块 + string ReqSubType = 2; // 请求协议函数 例如:login 对应项目中 user的模块中 api_login 的处理函数 + ErrorCode Code = 3; // 执行返回错误码 对应 errorcode.proto 枚举 + string Message = 4; // 错误消息 + string Data = 6; // 错误数据 +} diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 4d34f828b..09013d493 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -25,9 +25,9 @@ type Cache_UserData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"` - SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId"` - GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"` // DB_UserData UserData = 4; + Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"` + SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId,omitempty"` + GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"` // DB_UserData UserData = 4; } func (x *Cache_UserData) Reset() { @@ -88,18 +88,18 @@ type DB_UserData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` // ID - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"` - Uuid string `protobuf:"bytes,3,opt,name=uuid,proto3" json:"uuid"` //玩家唯一uuid - Binduid string `protobuf:"bytes,4,opt,name=binduid,proto3" json:"binduid"` //玩家账号 - Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name"` //玩家名 - Sid int32 `protobuf:"varint,6,opt,name=sid,proto3" json:"sid"` //区服id - Createip string `protobuf:"bytes,7,opt,name=createip,proto3" json:"createip"` //创建账号时的ip - Lastloginip string `protobuf:"bytes,8,opt,name=lastloginip,proto3" json:"lastloginip"` //最后一次登录时的ip - Ctime int64 `protobuf:"varint,9,opt,name=ctime,proto3" json:"ctime"` //玩家创号时间戳 - Logintime int64 `protobuf:"varint,10,opt,name=logintime,proto3" json:"logintime"` //最后一次登录时间 - FriendPoint int32 `protobuf:"varint,11,opt,name=FriendPoint,proto3" json:"FriendPoint"` //友情点 - Avatar int32 `protobuf:"varint,12,opt,name=avatar,proto3" json:"avatar"` //头像 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" bson:"_id"` // ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` + Uuid string `protobuf:"bytes,3,opt,name=uuid,proto3" json:"uuid,omitempty"` //玩家唯一uuid + Binduid string `protobuf:"bytes,4,opt,name=binduid,proto3" json:"binduid,omitempty"` //玩家账号 + Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty"` //玩家名 + Sid int32 `protobuf:"varint,6,opt,name=sid,proto3" json:"sid,omitempty"` //区服id + Createip string `protobuf:"bytes,7,opt,name=createip,proto3" json:"createip,omitempty"` //创建账号时的ip + Lastloginip string `protobuf:"bytes,8,opt,name=lastloginip,proto3" json:"lastloginip,omitempty"` //最后一次登录时的ip + Ctime int64 `protobuf:"varint,9,opt,name=ctime,proto3" json:"ctime,omitempty"` //玩家创号时间戳 + Logintime int64 `protobuf:"varint,10,opt,name=logintime,proto3" json:"logintime,omitempty"` //最后一次登录时间 + FriendPoint int32 `protobuf:"varint,11,opt,name=FriendPoint,proto3" json:"FriendPoint,omitempty"` //友情点 + Avatar int32 `protobuf:"varint,12,opt,name=avatar,proto3" json:"avatar,omitempty"` //头像 } func (x *DB_UserData) Reset() { diff --git a/pb/user_msg.pb.go b/pb/user_msg.pb.go index 3f6680d83..1ee7f9132 100644 --- a/pb/user_msg.pb.go +++ b/pb/user_msg.pb.go @@ -26,7 +26,7 @@ type UserLoginReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Sec string `protobuf:"bytes,1,opt,name=sec,proto3" json:"sec"` //密文 + Sec string `protobuf:"bytes,1,opt,name=sec,proto3" json:"sec,omitempty"` //密文 } func (x *UserLoginReq) Reset() { @@ -73,7 +73,7 @@ type UserLoginResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Data *Cache_UserData `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` + Data *Cache_UserData `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` } func (x *UserLoginResp) Reset() { @@ -120,7 +120,7 @@ type UserRegisterReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account"` + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` } func (x *UserRegisterReq) Reset() { @@ -167,8 +167,8 @@ type UserRegisterRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"` - Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account"` + Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"` + Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"` } func (x *UserRegisterRsp) Reset() { @@ -222,7 +222,7 @@ type UserLoadRsp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Data *Cache_UserData `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` + Data *Cache_UserData `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` } func (x *UserLoadRsp) Reset() { @@ -270,7 +270,7 @@ type UserCreateReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - NickName string `protobuf:"bytes,1,opt,name=NickName,proto3" json:"NickName"` //昵称 + NickName string `protobuf:"bytes,1,opt,name=NickName,proto3" json:"NickName,omitempty"` //昵称 } func (x *UserCreateReq) Reset() { diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index 1d61b7602..d6faea977 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -7,11 +7,14 @@ import ( "reflect" "sync" + jsoniter "github.com/json-iterator/go" + "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/utils/codec" "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes" @@ -128,16 +131,32 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM } returnValues := msgcheck.fn.Func.Call([]reflect.Value{msgcheck.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)}) // The return value for the method is an error. - code := returnValues[1].Int() - if pb.ErrorCode(code) != pb.ErrorCode_Success { + code := returnValues[1].Interface().(comm.ErrorCode) + if code.Code != pb.ErrorCode_Success { log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code) + reply.Code = code.Code + reply.Message = pb.GetErrorCodeMsg(code.Code) + if code.Data != nil { + if d, err := jsoniter.Marshal(code.Data); err != nil { + log.Errorf("HandleUserMsg:%s msg:%v code:%d err:%v", args.Method, msg, code, err) + return nil + } else { + reply.Data = codec.BytesToString(d) + } + } return nil } result := returnValues[0].Interface().(map[string]interface{}) - msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)}) + returnValues = msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)}) + errcode := pb.ErrorCode(returnValues[1].Int()) + if errcode != pb.ErrorCode_Success { + log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code) + reply.Code = errcode + reply.Message = pb.GetErrorCodeMsg(errcode) + return nil + } } else { reply.Code = pb.ErrorCode_ReqParameterError - // reply.Msg = pb.GetErrorCodeMsg(pb.ErrorCode_ReqParameterError) } return nil } diff --git a/sys/cache/init_test.go b/sys/cache/init_test.go index b2171305f..aebde276a 100644 --- a/sys/cache/init_test.go +++ b/sys/cache/init_test.go @@ -2,16 +2,19 @@ package cache_test import ( "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/sys/cache" "go_dreamfactory/sys/db" "os" - "reflect" "testing" + "time" "go_dreamfactory/utils" - "github.com/stretchr/testify/require" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" ) //测试环境下初始化db和cache 系统 @@ -24,36 +27,68 @@ func TestMain(m *testing.M) { fmt.Printf("err:%v\n", err) return } - // for i := 0; i < 50000; i++ { - // //go func() { - // _mail := &pb.DB_MailData{ - // ObjId: primitive.NewObjectID().Hex(), - // UserId: "uid123", - // Title: "系统邮件", + for i := 0; i < 50000; i++ { + //go func() { + _mail := &pb.DB_MailData{ + ObjId: primitive.NewObjectID().Hex(), + UserId: "uid123", + Title: "系统邮件", - // Contex: "恭喜获得专属礼包一份", - // CreateTime: uint64(time.Now().Unix()), - // DueTime: uint64(time.Now().Unix()) + 30*24*3600, - // Check: false, - // Reward: false, - // } - // //db.InsertModelLogs("mail", "uid123", _mail) - // //InsertModelLogs("mail", "uid123", _mail) - // data := &comm.Autogenerated{ - // ID: primitive.NewObjectID().Hex(), - // UID: "uid123", - // Act: string(comm.LogHandleType_Insert), - // } - // data.D = append(data.D, "mail") // D[0] - // data.D = append(data.D, _mail) // D[1] + Contex: "恭喜获得专属礼包一份", + CreateTime: uint64(time.Now().Unix()), + DueTime: uint64(time.Now().Unix()) + 30*24*3600, + Check: false, + Reward: false, + } + //db.InsertModelLogs("mail", "uid123", _mail) + db.Defsys.Mgo().InsertOne("mail", _mail) + data := &comm.Autogenerated{ + ID: primitive.NewObjectID().Hex(), + UID: "uid123", + Act: string(comm.LogHandleType_Insert), + } + data.D = append(data.D, "mail") // D[0] + data.D = append(data.D, _mail) // D[1] - // _, err1 := db.Defsys.Mgo().InsertOne("model_log", data) - // if err1 != nil { - // log.Errorf("insert model db err %v", err1) - // } - // //}() - // } - // time.Sleep(time.Second * 10) + _, err1 := db.Defsys.Mgo().InsertOne("model_log", data) + if err1 != nil { + log.Errorf("insert model db err %v", err1) + } + //}() + + /////////////////////////////////////// + filter := bson.M{ + "userid": "uid123", + "title": "系统邮件", + } + var nd *pb.DB_MailData + err := db.Defsys.Mgo().FindOne("mail", filter).Decode(&nd) + if err == nil { + nd.Check = true + nd.Reward = true + + data1 := &comm.Autogenerated{ + ID: primitive.NewObjectID().Hex(), + UID: "uid123", + Act: string(comm.LogHandleType_Update), + } + filter1 := bson.M{ + "userid": "uid123", + "title": "系统邮件", + } + data1.D = make([]interface{}, 0) + data1.D = append(data1.D, "mail") // D[0] + data1.D = append(data1.D, &filter1) // D[1] + data1.D = append(data1.D, nd) // D[2] + + _, err = db.Defsys.Mgo().InsertOne("model_log", data1) + if err != nil { + log.Errorf("insert model db err %v", err) + } + + } + } + time.Sleep(time.Second * 10) defer os.Exit(m.Run()) @@ -76,10 +111,3 @@ func TestSet(t *testing.T) { cache.Redis().HMSet("friend:222", data) } - -func TestGet(t *testing.T) { - result, err := cache.Redis().HGetAll("111", reflect.TypeOf(map[string]interface{}{})) - require.Nil(t, err) - - fmt.Println(result...) -}