test-errcode
wangchuxiao 2 years ago
commit 386c837f1a

@ -232,7 +232,7 @@ func main() {
if config.Config.Api.ListenIP != "" { if config.Config.Api.ListenIP != "" {
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort) address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)
} }
fmt.Println("start api server, address: ", address, "OpenIM version: ", constant.CurrentVersion) fmt.Println("start api server, address: ", address, ", OpenIM version: ", constant.CurrentVersion)
err := r.Run(address) err := r.Run(address)
if err != nil { if err != nil {
log.Error("", "api run failed ", address, err.Error()) log.Error("", "api run failed ", address, err.Error())

@ -25,6 +25,6 @@ func main() {
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort) address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)
} }
address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort) address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort)
fmt.Println("start cms api server, address: ", address, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start cms api server, address: ", address, ", OpenIM version: ", constant.CurrentVersion, "\n")
router.Run(address) router.Run(address)
} }

@ -70,7 +70,7 @@ func main() {
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort) address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort)
} }
address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort) address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort)
fmt.Println("start demo api server address: ", address, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start demo api server address: ", address, ", OpenIM version: ", constant.CurrentVersion, "\n")
go register.OnboardingProcessRoutine() go register.OnboardingProcessRoutine()
go register.ImportFriendRoutine() go register.ImportFriendRoutine()
err := r.Run(address) err := r.Run(address)

@ -21,7 +21,7 @@ func main() {
flag.Parse() flag.Parse()
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
fmt.Println("start rpc/msg_gateway server, port: ", *rpcPort, *wsPort, *prometheusPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start rpc/msg_gateway server, port: ", *rpcPort, *wsPort, *prometheusPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
gate.Init(*rpcPort, *wsPort) gate.Init(*rpcPort, *wsPort)
gate.Run(*prometheusPort) gate.Run(*prometheusPort)
wg.Wait() wg.Wait()

@ -17,7 +17,7 @@ func main() {
flag.Parse() flag.Parse()
log.NewPrivateLog(constant.LogFileName) log.NewPrivateLog(constant.LogFileName)
logic.Init() logic.Init()
fmt.Println("start msg_transfer server ", "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start msg_transfer server ", ", OpenIM version: ", constant.CurrentVersion, "\n")
logic.Run(*prometheusPort) logic.Run(*prometheusPort)
wg.Wait() wg.Wait()
} }

@ -18,7 +18,7 @@ func main() {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
log.NewPrivateLog(constant.LogFileName) log.NewPrivateLog(constant.LogFileName)
fmt.Println("start push rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start push rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
logic.Init(*rpcPort) logic.Init(*rpcPort)
logic.Run(*prometheusPort) logic.Run(*prometheusPort)
wg.Wait() wg.Wait()

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port") rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.AdminCmsPrometheusPort[0], "adminCMSPrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.AdminCmsPrometheusPort[0], "adminCMSPrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start cms rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start cms rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort) rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "RpcToken default listen port 10800") rpcPort := flag.Int("port", defaultPorts[0], "RpcToken default listen port 10800")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.AuthPrometheusPort[0], "authPrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.AuthPrometheusPort[0], "authPrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start auth rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start auth rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort) rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -15,7 +15,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "RpcToken default listen port 10800") rpcPort := flag.Int("port", defaultPorts[0], "RpcToken default listen port 10800")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.CachePrometheusPort[0], "cachePrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.CachePrometheusPort[0], "cachePrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start cache rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start cache rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := rpcCache.NewCacheServer(*rpcPort) rpcServer := rpcCache.NewCacheServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "RpcConversation default listen port 11300") rpcPort := flag.Int("port", defaultPorts[0], "RpcConversation default listen port 11300")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.ConversationPrometheusPort[0], "conversationPrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.ConversationPrometheusPort[0], "conversationPrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start conversation rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start conversation rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := rpcConversation.NewRpcConversationServer(*rpcPort) rpcServer := rpcConversation.NewRpcConversationServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "get RpcFriendPort from cmd,default 12000 as port") rpcPort := flag.Int("port", defaultPorts[0], "get RpcFriendPort from cmd,default 12000 as port")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.FriendPrometheusPort[0], "friendPrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.FriendPrometheusPort[0], "friendPrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start friend rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start friend rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := friend.NewFriendServer(*rpcPort) rpcServer := friend.NewFriendServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "get RpcGroupPort from cmd,default 16000 as port") rpcPort := flag.Int("port", defaultPorts[0], "get RpcGroupPort from cmd,default 16000 as port")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.GroupPrometheusPort[0], "groupPrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.GroupPrometheusPort[0], "groupPrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start group rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start group rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := group.NewGroupServer(*rpcPort) rpcServer := group.NewGroupServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port") rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.MessagePrometheusPort[0], "msgPrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.MessagePrometheusPort[0], "msgPrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start msg rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start msg rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := msg.NewRpcChatServer(*rpcPort) rpcServer := msg.NewRpcChatServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port") rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.OfficePrometheusPort[0], "officePrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.OfficePrometheusPort[0], "officePrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start office rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start office rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := rpc.NewOfficeServer(*rpcPort) rpcServer := rpc.NewOfficeServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "get RpcOrganizationPort from cmd,default 11200 as port") rpcPort := flag.Int("port", defaultPorts[0], "get RpcOrganizationPort from cmd,default 11200 as port")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.OrganizationPrometheusPort[0], "organizationPrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.OrganizationPrometheusPort[0], "organizationPrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start organization rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start organization rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := organization.NewServer(*rpcPort) rpcServer := organization.NewServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -14,7 +14,7 @@ func main() {
rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port") rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port")
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.UserPrometheusPort[0], "userPrometheusPort default listen port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.UserPrometheusPort[0], "userPrometheusPort default listen port")
flag.Parse() flag.Parse()
fmt.Println("start user rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") fmt.Println("start user rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
rpcServer := user.NewUserServer(*rpcPort) rpcServer := user.NewUserServer(*rpcPort)
go func() { go func() {
err := promePkg.StartPromeSrv(*prometheusPort) err := promePkg.StartPromeSrv(*prometheusPort)

@ -435,7 +435,20 @@ func GroupApplicationAcceptedNotification(req *pbGroup.GroupApplicationResponseR
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID, GroupApplicationAcceptedTips.OpUser) log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID, GroupApplicationAcceptedTips.OpUser)
return return
} }
groupNotification(constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, req.OpUserID, "", req.FromUserID, req.OperationID) groupNotification(constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, req.OpUserID, "", req.FromUserID, req.OperationID)
adminList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
if err != nil {
log.Error(req.OperationID, "GetOwnerManagerByGroupID failed", req.GroupID)
return
}
for _, v := range adminList {
if v.UserID == req.OpUserID {
continue
}
GroupApplicationAcceptedTips.ReceiverAs = 1
groupNotification(constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, req.OpUserID, "", v.UserID, req.OperationID)
}
} }
func GroupApplicationRejectedNotification(req *pbGroup.GroupApplicationResponseReq) { func GroupApplicationRejectedNotification(req *pbGroup.GroupApplicationResponseReq) {
@ -449,6 +462,18 @@ func GroupApplicationRejectedNotification(req *pbGroup.GroupApplicationResponseR
return return
} }
groupNotification(constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, req.OpUserID, "", req.FromUserID, req.OperationID) groupNotification(constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, req.OpUserID, "", req.FromUserID, req.OperationID)
adminList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
if err != nil {
log.Error(req.OperationID, "GetOwnerManagerByGroupID failed", req.GroupID)
return
}
for _, v := range adminList {
if v.UserID == req.OpUserID {
continue
}
GroupApplicationRejectedTips.ReceiverAs = 1
groupNotification(constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, req.OpUserID, "", v.UserID, req.OperationID)
}
} }
func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) { func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) {

@ -648,7 +648,7 @@ func unmarshalConfig(config interface{}, configName string) {
} else { } else {
bytes, err := ioutil.ReadFile(fmt.Sprintf("../config/%s", configName)) bytes, err := ioutil.ReadFile(fmt.Sprintf("../config/%s", configName))
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error() + configName)
} }
if err = yaml.Unmarshal(bytes, config); err != nil { if err = yaml.Unmarshal(bytes, config); err != nil {
panic(err.Error()) panic(err.Error())

@ -46,10 +46,10 @@ func key(dbAddress, dbName string) string {
} }
func init() { func init() {
//log.NewPrivateLog(constant.LogFileName)
var mongoClient *mongo.Client var mongoClient *mongo.Client
var err1 error var err1 error
//mysql init fmt.Println("init mysql redis mongo ")
initMysqlDB() initMysqlDB()
// mongo init // mongo init
// "mongodb://sysop:moon@localhost/records" // "mongodb://sysop:moon@localhost/records"
@ -84,45 +84,34 @@ func init() {
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err != nil { if err != nil {
fmt.Println(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
time.Sleep(time.Duration(30) * time.Second) time.Sleep(time.Duration(30) * time.Second)
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err1 != nil { if err1 != nil {
fmt.Println(" mongo.Connect retry failed, panic", err.Error(), uri) panic(err1.Error() + " mongo.Connect failed " + uri)
panic(err1.Error())
} }
} }
fmt.Println("mongo driver client init success: ", uri)
// mongodb create index // mongodb create index
if err := createMongoIndex(mongoClient, cSendLog, false, "send_id", "-send_time"); err != nil { if err := createMongoIndex(mongoClient, cSendLog, false, "send_id", "-send_time"); err != nil {
fmt.Println("send_id", "-send_time", "index create failed", err.Error()) panic(err.Error() + " index create failed " + cSendLog + " send_id, -send_time")
panic(err.Error())
} }
if err := createMongoIndex(mongoClient, cChat, false, "uid"); err != nil { if err := createMongoIndex(mongoClient, cChat, false, "uid"); err != nil {
fmt.Println("uid", " index create failed", err.Error()) fmt.Println(err.Error() + " index create failed " + cChat + " uid ")
//panic(err.Error())
} }
if err := createMongoIndex(mongoClient, cWorkMoment, true, "-create_time", "work_moment_id"); err != nil { if err := createMongoIndex(mongoClient, cWorkMoment, true, "-create_time", "work_moment_id"); err != nil {
fmt.Println("-create_time", "work_moment_id", "index create failed", err.Error()) panic(err.Error() + "index create failed " + cWorkMoment + " -create_time, work_moment_id")
panic(err.Error())
} }
if err := createMongoIndex(mongoClient, cWorkMoment, true, "work_moment_id"); err != nil { if err := createMongoIndex(mongoClient, cWorkMoment, true, "work_moment_id"); err != nil {
fmt.Println("work_moment_id", "index create failed", err.Error()) panic(err.Error() + "index create failed " + cWorkMoment + " work_moment_id ")
panic(err.Error())
} }
if err := createMongoIndex(mongoClient, cWorkMoment, false, "user_id", "-create_time"); err != nil { if err := createMongoIndex(mongoClient, cWorkMoment, false, "user_id", "-create_time"); err != nil {
fmt.Println("user_id", "-create_time", "index create failed", err.Error()) panic(err.Error() + "index create failed " + cWorkMoment + "user_id, -create_time")
panic(err.Error())
} }
if err := createMongoIndex(mongoClient, cTag, false, "user_id", "-create_time"); err != nil { if err := createMongoIndex(mongoClient, cTag, false, "user_id", "-create_time"); err != nil {
fmt.Println("user_id", "-create_time", "index create failed", err.Error()) panic(err.Error() + "index create failed " + cTag + " user_id, -create_time")
panic(err.Error())
} }
if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil { if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil {
fmt.Println("tag_id", "index create failed", err.Error()) panic(err.Error() + "index create failed " + cTag + " tag_id")
panic(err.Error())
} }
fmt.Println("createMongoIndex success")
DB.mongoClient = mongoClient DB.mongoClient = mongoClient
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
@ -136,7 +125,8 @@ func init() {
}) })
_, err = DB.RDB.Ping(ctx).Result() _, err = DB.RDB.Ping(ctx).Result()
if err != nil { if err != nil {
panic(err.Error()) fmt.Println("redis cluster failed address ", config.Config.Redis.DBAddress)
panic(err.Error() + " redis cluster " + config.Config.Redis.DBUserName + config.Config.Redis.DBPassWord)
} }
} else { } else {
DB.RDB = go_redis.NewClient(&go_redis.Options{ DB.RDB = go_redis.NewClient(&go_redis.Options{
@ -148,7 +138,7 @@ func init() {
}) })
_, err = DB.RDB.Ping(ctx).Result() _, err = DB.RDB.Ping(ctx).Result()
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error() + " redis " + config.Config.Redis.DBAddress[0] + config.Config.Redis.DBUserName + config.Config.Redis.DBPassWord)
} }
} }
// 强一致性缓存当一个key被标记删除其他请求线程会被锁住轮询直到新的key生成适合各种同步的拉取, 如果弱一致可能导致拉取还是老数据,毫无意义 // 强一致性缓存当一个key被标记删除其他请求线程会被锁住轮询直到新的key生成适合各种同步的拉取, 如果弱一致可能导致拉取还是老数据,毫无意义
@ -158,6 +148,8 @@ func init() {
// 弱一致性缓存当一个key被标记删除其他请求线程直接返回该key的value适合高频并且生成很缓存很慢的情况 如大群发消息缓存的缓存 // 弱一致性缓存当一个key被标记删除其他请求线程直接返回该key的value适合高频并且生成很缓存很慢的情况 如大群发消息缓存的缓存
DB.WeakRc = rockscache.NewClient(DB.RDB, rockscache.NewDefaultOptions()) DB.WeakRc = rockscache.NewClient(DB.RDB, rockscache.NewDefaultOptions())
DB.WeakRc.Options.StrongConsistency = false DB.WeakRc.Options.StrongConsistency = false
fmt.Println("init mysql redis mongo ok ")
} }
func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error { func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error {

@ -22,37 +22,26 @@ func (w Writer) Printf(format string, args ...interface{}) {
} }
func initMysqlDB() { func initMysqlDB() {
fmt.Println("init mysqlDB start")
//When there is no open IM database, connect to the mysql built-in database to create openIM database
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql") config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
var db *gorm.DB var db *gorm.DB
var err1 error var err1 error
db, err := gorm.Open(mysql.Open(dsn), nil) db, err := gorm.Open(mysql.Open(dsn), nil)
if err != nil {
fmt.Println("Open failed ", err.Error(), dsn)
}
if err != nil { if err != nil {
time.Sleep(time.Duration(30) * time.Second) time.Sleep(time.Duration(30) * time.Second)
db, err1 = gorm.Open(mysql.Open(dsn), nil) db, err1 = gorm.Open(mysql.Open(dsn), nil)
if err1 != nil { if err1 != nil {
fmt.Println("Open failed ", err1.Error(), dsn) panic(err1.Error() + " open failed " + dsn)
panic(err1.Error())
} }
} }
//Check the database and table during initialization
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName) sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
fmt.Println("exec sql: ", sql, " begin")
err = db.Exec(sql).Error err = db.Exec(sql).Error
if err != nil { if err != nil {
fmt.Println("Exec failed ", err.Error(), sql) panic(err.Error() + " Exec failed " + sql)
panic(err.Error())
} }
fmt.Println("exec sql: ", sql, " end")
dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName) config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
newLogger := logger.New( newLogger := logger.New(
Writer{}, Writer{},
logger.Config{ logger.Config{
@ -66,20 +55,18 @@ func initMysqlDB() {
Logger: newLogger, Logger: newLogger,
}) })
if err != nil { if err != nil {
fmt.Println("Open failed ", err.Error(), dsn) panic(err.Error() + " Open failed " + dsn)
panic(err.Error())
} }
sqlDB, err := db.DB() sqlDB, err := db.DB()
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error() + " db.DB() failed ")
} }
sqlDB.SetConnMaxLifetime(time.Second * time.Duration(config.Config.Mysql.DBMaxLifeTime)) sqlDB.SetConnMaxLifetime(time.Second * time.Duration(config.Config.Mysql.DBMaxLifeTime))
sqlDB.SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns) sqlDB.SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns)
sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns) sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns)
fmt.Println("open mysql ok ", dsn)
db.AutoMigrate( db.AutoMigrate(
&Register{}, &Register{},
&Friend{}, &Friend{},
@ -94,99 +81,69 @@ func initMysqlDB() {
db.Set("gorm:table_options", "collation=utf8_unicode_ci") db.Set("gorm:table_options", "collation=utf8_unicode_ci")
if !db.Migrator().HasTable(&Friend{}) { if !db.Migrator().HasTable(&Friend{}) {
fmt.Println("CreateTable Friend")
db.Migrator().CreateTable(&Friend{}) db.Migrator().CreateTable(&Friend{})
} }
if !db.Migrator().HasTable(&FriendRequest{}) { if !db.Migrator().HasTable(&FriendRequest{}) {
fmt.Println("CreateTable FriendRequest")
db.Migrator().CreateTable(&FriendRequest{}) db.Migrator().CreateTable(&FriendRequest{})
} }
if !db.Migrator().HasTable(&Group{}) { if !db.Migrator().HasTable(&Group{}) {
fmt.Println("CreateTable Group")
db.Migrator().CreateTable(&Group{}) db.Migrator().CreateTable(&Group{})
} }
if !db.Migrator().HasTable(&GroupMember{}) { if !db.Migrator().HasTable(&GroupMember{}) {
fmt.Println("CreateTable GroupMember")
db.Migrator().CreateTable(&GroupMember{}) db.Migrator().CreateTable(&GroupMember{})
} }
if !db.Migrator().HasTable(&GroupRequest{}) { if !db.Migrator().HasTable(&GroupRequest{}) {
fmt.Println("CreateTable GroupRequest")
db.Migrator().CreateTable(&GroupRequest{}) db.Migrator().CreateTable(&GroupRequest{})
} }
if !db.Migrator().HasTable(&User{}) { if !db.Migrator().HasTable(&User{}) {
fmt.Println("CreateTable User")
db.Migrator().CreateTable(&User{}) db.Migrator().CreateTable(&User{})
} }
if !db.Migrator().HasTable(&Black{}) { if !db.Migrator().HasTable(&Black{}) {
fmt.Println("CreateTable Black")
db.Migrator().CreateTable(&Black{}) db.Migrator().CreateTable(&Black{})
} }
if !db.Migrator().HasTable(&ChatLog{}) { if !db.Migrator().HasTable(&ChatLog{}) {
fmt.Println("CreateTable ChatLog")
db.Migrator().CreateTable(&ChatLog{}) db.Migrator().CreateTable(&ChatLog{})
} }
if !db.Migrator().HasTable(&Register{}) { if !db.Migrator().HasTable(&Register{}) {
fmt.Println("CreateTable Register")
db.Migrator().CreateTable(&Register{}) db.Migrator().CreateTable(&Register{})
} }
if !db.Migrator().HasTable(&Conversation{}) { if !db.Migrator().HasTable(&Conversation{}) {
fmt.Println("CreateTable Conversation")
db.Migrator().CreateTable(&Conversation{}) db.Migrator().CreateTable(&Conversation{})
} }
if !db.Migrator().HasTable(&Department{}) { if !db.Migrator().HasTable(&Department{}) {
fmt.Println("CreateTable Department")
db.Migrator().CreateTable(&Department{}) db.Migrator().CreateTable(&Department{})
} }
if !db.Migrator().HasTable(&OrganizationUser{}) { if !db.Migrator().HasTable(&OrganizationUser{}) {
fmt.Println("CreateTable OrganizationUser")
db.Migrator().CreateTable(&OrganizationUser{}) db.Migrator().CreateTable(&OrganizationUser{})
} }
if !db.Migrator().HasTable(&DepartmentMember{}) { if !db.Migrator().HasTable(&DepartmentMember{}) {
fmt.Println("CreateTable DepartmentMember")
db.Migrator().CreateTable(&DepartmentMember{}) db.Migrator().CreateTable(&DepartmentMember{})
} }
if !db.Migrator().HasTable(&AppVersion{}) { if !db.Migrator().HasTable(&AppVersion{}) {
fmt.Println("CreateTable DepartmentMember")
db.Migrator().CreateTable(&AppVersion{}) db.Migrator().CreateTable(&AppVersion{})
} }
if !db.Migrator().HasTable(&BlackList{}) { if !db.Migrator().HasTable(&BlackList{}) {
fmt.Println("CreateTable BlackList")
db.Migrator().CreateTable(&BlackList{}) db.Migrator().CreateTable(&BlackList{})
} }
if !db.Migrator().HasTable(&IpLimit{}) { if !db.Migrator().HasTable(&IpLimit{}) {
fmt.Println("CreateTable IpLimit")
db.Migrator().CreateTable(&IpLimit{}) db.Migrator().CreateTable(&IpLimit{})
} }
if !db.Migrator().HasTable(&UserIpLimit{}) { if !db.Migrator().HasTable(&UserIpLimit{}) {
fmt.Println("CreateTable UserIpLimit")
db.Migrator().CreateTable(&UserIpLimit{}) db.Migrator().CreateTable(&UserIpLimit{})
} }
if !db.Migrator().HasTable(&RegisterAddFriend{}) { if !db.Migrator().HasTable(&RegisterAddFriend{}) {
fmt.Println("CreateTable RegisterAddFriend")
db.Migrator().CreateTable(&RegisterAddFriend{}) db.Migrator().CreateTable(&RegisterAddFriend{})
} }
if !db.Migrator().HasTable(&Invitation{}) { if !db.Migrator().HasTable(&Invitation{}) {
fmt.Println("CreateTable Invitation")
db.Migrator().CreateTable(&Invitation{}) db.Migrator().CreateTable(&Invitation{})
} }
if !db.Migrator().HasTable(&ClientInitConfig{}) { if !db.Migrator().HasTable(&ClientInitConfig{}) {
fmt.Println("CreateTable ClientInitConfig")
db.Migrator().CreateTable(&ClientInitConfig{}) db.Migrator().CreateTable(&ClientInitConfig{})
} }
if !db.Migrator().HasTable(&UserIpRecord{}) { if !db.Migrator().HasTable(&UserIpRecord{}) {
fmt.Println("CreateTable Friend")
db.Migrator().CreateTable(&UserIpRecord{}) db.Migrator().CreateTable(&UserIpRecord{})
} }
DB.MysqlDB.db = db DB.MysqlDB.db = db
return
} }
func (m *mysqlDB) DefaultGormDB() *gorm.DB { func (m *mysqlDB) DefaultGormDB() *gorm.DB {

@ -8,7 +8,6 @@ package kafka
import ( import (
"context" "context"
"fmt"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
) )
@ -29,7 +28,7 @@ func NewMConsumerGroup(consumerConfig *MConsumerGroupConfig, topics, addrs []str
config.Version = consumerConfig.KafkaVersion config.Version = consumerConfig.KafkaVersion
config.Consumer.Offsets.Initial = consumerConfig.OffsetsInitial config.Consumer.Offsets.Initial = consumerConfig.OffsetsInitial
config.Consumer.Return.Errors = consumerConfig.IsReturnErr config.Consumer.Return.Errors = consumerConfig.IsReturnErr
fmt.Println("init address is ", addrs, "topics is ", topics) //fmt.Println("init address is ", addrs, "topics is ", topics)
consumerGroup, err := sarama.NewConsumerGroup(addrs, groupID, config) consumerGroup, err := sarama.NewConsumerGroup(addrs, groupID, config)
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())

File diff suppressed because it is too large Load Diff

@ -330,6 +330,7 @@ message GroupApplicationAcceptedTips{
GroupInfo group = 1; GroupInfo group = 1;
GroupMemberFullInfo opUser = 2; GroupMemberFullInfo opUser = 2;
string handleMsg = 4; string handleMsg = 4;
int32 receiverAs = 5; // admin(==1) or applicant(==0)
} }
// OnApplicationGroupRejected() // OnApplicationGroupRejected()
@ -337,6 +338,7 @@ message GroupApplicationRejectedTips{
GroupInfo group = 1; GroupInfo group = 1;
GroupMemberFullInfo opUser = 2; GroupMemberFullInfo opUser = 2;
string handleMsg = 4; string handleMsg = 4;
int32 receiverAs = 5; // admin(==1) or applicant(==0)
} }
// OnTransferGroupOwner() // OnTransferGroupOwner()

Loading…
Cancel
Save