MCPcopy
hub / github.com/openimsdk/open-im-server / Main

Function Main

tools/seq/internal/main.go:68–249  ·  view source on GitHub ↗
(conf string, del time.Duration)

Source from the content-addressed store, hash-verified

66}
67
68func Main(conf string, del time.Duration) error {
69 redisConfig, err := readConfig[config.Redis](conf, cmd.RedisConfigFileName)
70 if err != nil {
71 return err
72 }
73 mongodbConfig, err := readConfig[config.Mongo](conf, cmd.MongodbConfigFileName)
74 if err != nil {
75 return err
76 }
77 ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
78 defer cancel()
79 rdb, err := redisutil.NewRedisClient(ctx, redisConfig.Build())
80 if err != nil {
81 return err
82 }
83 mgocli, err := mongoutil.NewMongoDB(ctx, mongodbConfig.Build())
84 if err != nil {
85 return err
86 }
87 versionColl := mgocli.GetDB().Collection(dataVersionCollection)
88 converted, err := CheckVersion(versionColl, seqKey, seqVersion)
89 if err != nil {
90 return err
91 }
92 if converted {
93 fmt.Println("[seq] seq data has been converted")
94 return nil
95 }
96 if _, err := mgo.NewSeqConversationMongo(mgocli.GetDB()); err != nil {
97 return err
98 }
99 cSeq, err := mgo.NewSeqConversationMongo(mgocli.GetDB())
100 if err != nil {
101 return err
102 }
103 uSeq, err := mgo.NewSeqUserMongo(mgocli.GetDB())
104 if err != nil {
105 return err
106 }
107 uSpitHasReadSeq := func(id string) (conversationID string, userID string, err error) {
108 // HasReadSeq + userID + ":" + conversationID
109 arr := strings.Split(id, ":")
110 if len(arr) != 2 || arr[0] == "" || arr[1] == "" {
111 return "", "", fmt.Errorf("invalid has read seq id %s", id)
112 }
113 userID = arr[0]
114 conversationID = arr[1]
115 return
116 }
117 uSpitConversationUserMinSeq := func(id string) (conversationID string, userID string, err error) {
118 // ConversationUserMinSeq + conversationID + "u:" + userID
119 arr := strings.Split(id, "u:")
120 if len(arr) != 2 || arr[0] == "" || arr[1] == "" {
121 return "", "", fmt.Errorf("invalid has read seq id %s", id)
122 }
123 conversationID = arr[0]
124 userID = arr[1]
125 return

Callers 1

mainFunction · 0.92

Calls 15

NewSeqConversationMongoFunction · 0.92
NewSeqUserMongoFunction · 0.92
readConfigFunction · 0.85
CheckVersionFunction · 0.85
seqRedisToMongoFunction · 0.85
SetVersionFunction · 0.85
AddMethod · 0.80
DoneMethod · 0.80
SubMethod · 0.80
ErrMethod · 0.80
GetUserReadSeqMethod · 0.65
SetUserReadSeqMethod · 0.65

Tested by

no test coverage detected