diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index e9e253338..a4db0e616 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -227,7 +227,7 @@ func main() { if config.Config.Api.ListenIP != "" { address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort) } - fmt.Println("start api server, address: ", address, "\n") + fmt.Println("start api server, address: ", address, "OpenIM version: ", constant.CurrentVersion, "\n") err := r.Run(address) if err != nil { log.Error("", "api run failed ", address, err.Error()) diff --git a/cmd/open_im_cms_api/main.go b/cmd/open_im_cms_api/main.go index deaebc196..94c662b0b 100644 --- a/cmd/open_im_cms_api/main.go +++ b/cmd/open_im_cms_api/main.go @@ -2,6 +2,7 @@ package main import ( "Open_IM/internal/cms_api" + "Open_IM/pkg/common/constant" "Open_IM/pkg/utils" "flag" "fmt" @@ -24,6 +25,6 @@ func main() { address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort) } address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort) - fmt.Println("start cms api server, address: ", address, "\n") + fmt.Println("start cms api server, address: ", address, "OpenIM version: ", constant.CurrentVersion, "\n") router.Run(address) } diff --git a/cmd/open_im_demo/main.go b/cmd/open_im_demo/main.go index 703a9a74d..0e2dbaea6 100644 --- a/cmd/open_im_demo/main.go +++ b/cmd/open_im_demo/main.go @@ -71,7 +71,7 @@ func main() { address = config.Config.Api.ListenIP + ":" + strconv.Itoa(*ginPort) } address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort) - fmt.Println("start demo api server address: ", address, "\n") + fmt.Println("start demo api server address: ", address, "OpenIM version: ", constant.CurrentVersion, "\n") go register.OnboardingProcessRoutine() go register.ImportFriendRoutine() err := r.Run(address) diff --git a/cmd/open_im_msg_gateway/main.go b/cmd/open_im_msg_gateway/main.go index cc6621ffc..44f55ce19 100644 --- a/cmd/open_im_msg_gateway/main.go +++ b/cmd/open_im_msg_gateway/main.go @@ -21,7 +21,7 @@ func main() { flag.Parse() var wg sync.WaitGroup wg.Add(1) - fmt.Println("start rpc/msg_gateway server, port: ", *rpcPort, *wsPort, *prometheusPort, "\n") + fmt.Println("start rpc/msg_gateway server, port: ", *rpcPort, *wsPort, *prometheusPort, "OpenIM version: ", constant.CurrentVersion, "\n") gate.Init(*rpcPort, *wsPort) gate.Run(*prometheusPort) wg.Wait() diff --git a/cmd/open_im_msg_transfer/main.go b/cmd/open_im_msg_transfer/main.go index 4b501406e..b11fa5a1a 100644 --- a/cmd/open_im_msg_transfer/main.go +++ b/cmd/open_im_msg_transfer/main.go @@ -17,7 +17,7 @@ func main() { flag.Parse() log.NewPrivateLog(constant.LogFileName) logic.Init() - fmt.Println("start msg_transfer server \n") + fmt.Println("start msg_transfer server ", "OpenIM version: ", constant.CurrentVersion, "\n") logic.Run(*prometheusPort) wg.Wait() } diff --git a/cmd/open_im_push/main.go b/cmd/open_im_push/main.go index 09ffde048..b14581690 100644 --- a/cmd/open_im_push/main.go +++ b/cmd/open_im_push/main.go @@ -18,7 +18,7 @@ func main() { var wg sync.WaitGroup wg.Add(1) log.NewPrivateLog(constant.LogFileName) - fmt.Println("start push rpc server, port: ", *rpcPort, "\n") + fmt.Println("start push rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") logic.Init(*rpcPort) logic.Run(*prometheusPort) wg.Wait() diff --git a/cmd/rpc/open_im_admin_cms/main.go b/cmd/rpc/open_im_admin_cms/main.go index 1f2dfb51c..f35b71300 100644 --- a/cmd/rpc/open_im_admin_cms/main.go +++ b/cmd/rpc/open_im_admin_cms/main.go @@ -3,6 +3,7 @@ package main import ( rpcMessageCMS "Open_IM/internal/rpc/admin_cms" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.AdminCmsPrometheusPort[0], "adminCMSPrometheusPort default listen port") flag.Parse() - fmt.Println("start cms rpc server, port: ", *rpcPort, "\n") + fmt.Println("start cms rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_auth/main.go b/cmd/rpc/open_im_auth/main.go index 063cda4a1..56f2df0df 100644 --- a/cmd/rpc/open_im_auth/main.go +++ b/cmd/rpc/open_im_auth/main.go @@ -3,6 +3,7 @@ package main import ( rpcAuth "Open_IM/internal/rpc/auth" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { 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") flag.Parse() - fmt.Println("start auth rpc server, port: ", *rpcPort, "\n") + fmt.Println("start auth rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_cache/main.go b/cmd/rpc/open_im_cache/main.go index 185e8fac1..7df5d80f7 100644 --- a/cmd/rpc/open_im_cache/main.go +++ b/cmd/rpc/open_im_cache/main.go @@ -3,6 +3,7 @@ package main import ( rpcCache "Open_IM/internal/rpc/cache" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" @@ -14,7 +15,7 @@ func main() { 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") flag.Parse() - fmt.Println("start cache rpc server, port: ", *rpcPort, "\n") + fmt.Println("start cache rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := rpcCache.NewCacheServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_conversation/main.go b/cmd/rpc/open_im_conversation/main.go index 268aa5ed9..f3c746ade 100644 --- a/cmd/rpc/open_im_conversation/main.go +++ b/cmd/rpc/open_im_conversation/main.go @@ -3,6 +3,7 @@ package main import ( rpcConversation "Open_IM/internal/rpc/conversation" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { 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") flag.Parse() - fmt.Println("start conversation rpc server, port: ", *rpcPort, "\n") + fmt.Println("start conversation rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := rpcConversation.NewRpcConversationServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_friend/main.go b/cmd/rpc/open_im_friend/main.go index 489b8541d..ae5ae0090 100644 --- a/cmd/rpc/open_im_friend/main.go +++ b/cmd/rpc/open_im_friend/main.go @@ -3,6 +3,7 @@ package main import ( "Open_IM/internal/rpc/friend" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { 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") flag.Parse() - fmt.Println("start friend rpc server, port: ", *rpcPort, "\n") + fmt.Println("start friend rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := friend.NewFriendServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_group/main.go b/cmd/rpc/open_im_group/main.go index 8e32f48ab..42b7f1f5c 100644 --- a/cmd/rpc/open_im_group/main.go +++ b/cmd/rpc/open_im_group/main.go @@ -3,6 +3,7 @@ package main import ( "Open_IM/internal/rpc/group" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { 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") flag.Parse() - fmt.Println("start group rpc server, port: ", *rpcPort, "\n") + fmt.Println("start group rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := group.NewGroupServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_msg/main.go b/cmd/rpc/open_im_msg/main.go index 34294e546..a9d87a7ba 100644 --- a/cmd/rpc/open_im_msg/main.go +++ b/cmd/rpc/open_im_msg/main.go @@ -3,6 +3,7 @@ package main import ( "Open_IM/internal/rpc/msg" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.MessagePrometheusPort[0], "msgPrometheusPort default listen port") flag.Parse() - fmt.Println("start msg rpc server, port: ", *rpcPort, "\n") + fmt.Println("start msg rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := msg.NewRpcChatServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_office/main.go b/cmd/rpc/open_im_office/main.go index 369328319..0af5444d6 100644 --- a/cmd/rpc/open_im_office/main.go +++ b/cmd/rpc/open_im_office/main.go @@ -3,6 +3,7 @@ package main import ( rpc "Open_IM/internal/rpc/office" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.OfficePrometheusPort[0], "officePrometheusPort default listen port") flag.Parse() - fmt.Println("start office rpc server, port: ", *rpcPort, "\n") + fmt.Println("start office rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := rpc.NewOfficeServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_organization/main.go b/cmd/rpc/open_im_organization/main.go index 3b748c010..5dc27ccd5 100644 --- a/cmd/rpc/open_im_organization/main.go +++ b/cmd/rpc/open_im_organization/main.go @@ -3,6 +3,7 @@ package main import ( "Open_IM/internal/rpc/organization" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { 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") flag.Parse() - fmt.Println("start organization rpc server, port: ", *rpcPort, "\n") + fmt.Println("start organization rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := organization.NewServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/cmd/rpc/open_im_user/main.go b/cmd/rpc/open_im_user/main.go index 61fc25790..3e64ac805 100644 --- a/cmd/rpc/open_im_user/main.go +++ b/cmd/rpc/open_im_user/main.go @@ -3,6 +3,7 @@ package main import ( "Open_IM/internal/rpc/user" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" promePkg "Open_IM/pkg/common/prometheus" "flag" "fmt" @@ -13,7 +14,7 @@ func main() { rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port") prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.UserPrometheusPort[0], "userPrometheusPort default listen port") flag.Parse() - fmt.Println("start user rpc server, port: ", *rpcPort, "\n") + fmt.Println("start user rpc server, port: ", *rpcPort, "OpenIM version: ", constant.CurrentVersion, "\n") rpcServer := user.NewUserServer(*rpcPort) go func() { err := promePkg.StartPromeSrv(*prometheusPort) diff --git a/internal/cms_api/admin/admin.go b/internal/cms_api/admin/admin.go index 7d4c450fb..2c98502da 100644 --- a/internal/cms_api/admin/admin.go +++ b/internal/cms_api/admin/admin.go @@ -3,6 +3,7 @@ package admin import ( apiStruct "Open_IM/pkg/cms_api_struct" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbAdmin "Open_IM/pkg/proto/admin_cms" @@ -25,6 +26,7 @@ var ( ) func init() { + log.NewPrivateLog(constant.LogFileName) operationID := utils.OperationIDGenerator() log.NewInfo(operationID, utils.GetSelfFuncName(), "minio config: ", config.Config.Credential.Minio) var initUrl string diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index ecc53ea26..3642b31c3 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -336,3 +336,5 @@ const LogFileName = "OpenIM.log" const StatisticsTimeInterval = 60 const MaxNotificationNum = 100 + +const CurrentVersion = "v2.3.3" diff --git a/pkg/common/db/mysql.go b/pkg/common/db/mysql.go index 72641e37d..75d3e6887 100644 --- a/pkg/common/db/mysql.go +++ b/pkg/common/db/mysql.go @@ -31,25 +31,26 @@ func initMysqlDB() { var err1 error db, err := gorm.Open(mysql.Open(dsn), nil) if err != nil { - fmt.Println("0", "Open failed ", err.Error(), dsn) + fmt.Println("Open failed ", err.Error(), dsn) } if err != nil { time.Sleep(time.Duration(30) * time.Second) db, err1 = gorm.Open(mysql.Open(dsn), nil) if err1 != nil { - fmt.Println("0", "Open failed ", err1.Error(), dsn) + fmt.Println("Open failed ", err1.Error(), dsn) panic(err1.Error()) } } - fmt.Println("init db", db) + //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) + fmt.Println("exec sql: ", sql, " begin") err = db.Exec(sql).Error if err != nil { - fmt.Println("0", "Exec failed ", err.Error(), sql) + fmt.Println("Exec failed ", err.Error(), sql) panic(err.Error()) } - fmt.Println(sql) + fmt.Println("exec sql: ", sql, " end") 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) @@ -66,20 +67,20 @@ func initMysqlDB() { Logger: newLogger, }) if err != nil { - fmt.Println("0", "Open failed ", err.Error(), dsn) + fmt.Println("Open failed ", err.Error(), dsn) panic(err.Error()) } - fmt.Println("init db2", db) + sqlDB, err := db.DB() if err != nil { panic(err.Error()) } - fmt.Println("init sqlDB", sqlDB) + sqlDB.SetConnMaxLifetime(time.Second * time.Duration(config.Config.Mysql.DBMaxLifeTime)) sqlDB.SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns) sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns) - fmt.Println("open db ok ", dsn) + fmt.Println("open mysql ok ", dsn) db.AutoMigrate( &Register{}, &Friend{}, diff --git a/pkg/utils/get_server_ip.go b/pkg/utils/get_server_ip.go index 63156f26f..b8056af9d 100644 --- a/pkg/utils/get_server_ip.go +++ b/pkg/utils/get_server_ip.go @@ -2,7 +2,6 @@ package utils import ( "errors" - "fmt" "net" ) @@ -11,14 +10,12 @@ var ServerIP = "" func GetLocalIP() (string, error) { addrs, err := net.InterfaceAddrs() if err != nil { - return "", err } for _, address := range addrs { if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ipnet.IP.To4() != nil { - fmt.Println(ipnet.IP.String()) return ipnet.IP.String(), nil } }