From a61979e9858bc0b55a39a47fdd3130f6de6d9715 Mon Sep 17 00:00:00 2001 From: duanhf2012 <6549168@qq.com> Date: Wed, 17 May 2023 11:26:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF=E9=98=9F?= =?UTF-8?q?=E5=88=97=E6=9C=8D=E5=8A=A1=E6=8C=81=E4=B9=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../messagequeueservice/MongoPersist.go | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/sysservice/messagequeueservice/MongoPersist.go b/sysservice/messagequeueservice/MongoPersist.go index c329ccf..acbdcda 100644 --- a/sysservice/messagequeueservice/MongoPersist.go +++ b/sysservice/messagequeueservice/MongoPersist.go @@ -1,18 +1,49 @@ package messagequeueservice import ( + "errors" "fmt" "github.com/duanhf2012/origin/log" "github.com/duanhf2012/origin/service" "github.com/duanhf2012/origin/sysmodule/mongodbmodule" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" - "sunserver/common/util" "time" ) const MaxDays = 180 +type DataType interface { + int | uint | int64 | uint64 | float32 | float64 | int32 | uint32 | int16 | uint16 +} + +func convertToNumber[DType DataType](val interface{}) (error, DType) { + switch val.(type) { + case int64: + return nil, DType(val.(int64)) + case int: + return nil, DType(val.(int)) + case uint: + return nil, DType(val.(uint)) + case uint64: + return nil, DType(val.(uint64)) + case float32: + return nil, DType(val.(float32)) + case float64: + return nil, DType(val.(float64)) + case int32: + return nil, DType(val.(int32)) + case uint32: + return nil, DType(val.(uint32)) + case int16: + return nil, DType(val.(int16)) + case uint16: + return nil, DType(val.(uint16)) + } + + return errors.New("unsupported type"), 0 +} + type MongoPersist struct { service.Module mongo mongodbmodule.MongoModule @@ -363,7 +394,7 @@ func (mp *MongoPersist) GetIndex(topicData *TopicData) uint64 { for _, e := range document { if e.Key == "_id" { - errC, seq := util.ConvertToNumber[uint64](e.Value) + errC, seq := convertToNumber[uint64](e.Value) if errC != nil { log.Error("value is error:%s,%+v, ", errC.Error(), e.Value) }