mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-21 04:09:17 +08:00
group update
This commit is contained in:
parent
0d3984233b
commit
5af01e4da1
@ -41,18 +41,34 @@ type groupServer struct {
|
|||||||
rpcRegisterName string
|
rpcRegisterName string
|
||||||
etcdSchema string
|
etcdSchema string
|
||||||
etcdAddr []string
|
etcdAddr []string
|
||||||
imdb.GroupInterface
|
group model.GroupInterface
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupServer(port int) *groupServer {
|
func NewGroupServer(port int) *groupServer {
|
||||||
log.NewPrivateLog(constant.LogFileName)
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &groupServer{
|
g := groupServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||||
}
|
}
|
||||||
|
//mysql init
|
||||||
|
var mysql imdb.Mysql
|
||||||
|
var groupModel imdb.Group
|
||||||
|
err := mysql.InitConn().AutoMigrateModel(&groupModel)
|
||||||
|
if err != nil {
|
||||||
|
panic("db init err:" + err.Error())
|
||||||
|
}
|
||||||
|
if mysql.GormConn() != nil {
|
||||||
|
groupModel.DB = mysql.GormConn()
|
||||||
|
} else {
|
||||||
|
panic("db init err:" + "conn is nil")
|
||||||
|
}
|
||||||
|
//redis
|
||||||
|
//mongo
|
||||||
|
g.group = model.NewGroupController(groupModel)
|
||||||
|
|
||||||
|
return &g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) Run() {
|
func (s *groupServer) Run() {
|
||||||
@ -70,6 +86,7 @@ func (s *groupServer) Run() {
|
|||||||
panic("listening err:" + err.Error() + s.rpcRegisterName)
|
panic("listening err:" + err.Error() + s.rpcRegisterName)
|
||||||
}
|
}
|
||||||
log.NewInfo("", "listen network success, ", address, listener)
|
log.NewInfo("", "listen network success, ", address, listener)
|
||||||
|
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
//grpc server
|
//grpc server
|
||||||
recvSize := 1024 * 1024 * constant.GroupRPCRecvSize
|
recvSize := 1024 * 1024 * constant.GroupRPCRecvSize
|
||||||
|
@ -36,14 +36,14 @@ type MySqlDatabase struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MySqlDatabase) Delete(ctx context.Context, groupIDs []string) error {
|
func (m *MySqlDatabase) Delete(ctx context.Context, groupIDs []string) error {
|
||||||
panic("implement me")
|
return m.Delete(ctx, groupIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMySqlDatabase(db mysql.GroupModelInterface) DataBase {
|
func NewMySqlDatabase(db mysql.GroupModelInterface) DataBase {
|
||||||
return &MySqlDatabase{db}
|
return &MySqlDatabase{db}
|
||||||
}
|
}
|
||||||
func (m *MySqlDatabase) DeleteTx(ctx context.Context, groupIDs []string) error {
|
func (m *MySqlDatabase) DeleteTx(ctx context.Context, groupIDs []string) error {
|
||||||
return nil
|
return m.Delete(ctx, groupIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupController(groupModel mysql.GroupModelInterface, rdb redis.UniversalClient, mdb *mongo.Client) *GroupController {
|
func NewGroupController(groupModel mysql.GroupModelInterface, rdb redis.UniversalClient, mdb *mongo.Client) *GroupController {
|
||||||
|
@ -10,7 +10,18 @@ import (
|
|||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConnectToDB() *gorm.DB {
|
type Mysql struct {
|
||||||
|
gormConn *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mysql) GormConn() *gorm.DB {
|
||||||
|
return m.gormConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mysql) SetGormConn(gormConn *gorm.DB) {
|
||||||
|
m.gormConn = gormConn
|
||||||
|
}
|
||||||
|
func (m *Mysql) InitConn() *Mysql {
|
||||||
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
|
||||||
@ -51,18 +62,22 @@ func ConnectToDB() *gorm.DB {
|
|||||||
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)
|
||||||
return db
|
m.SetGormConn(db)
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
//models := []interface{}{&Friend{}, &FriendRequest{}, &Group{}, &GroupMember{}, &GroupRequest{},
|
//models := []interface{}{&Friend{}, &FriendRequest{}, &Group{}, &GroupMember{}, &GroupRequest{},
|
||||||
// &User{}, &Black{}, &ChatLog{}, &Conversation{}, &AppVersion{}}
|
// &User{}, &Black{}, &ChatLog{}, &Conversation{}, &AppVersion{}}
|
||||||
|
|
||||||
func initModel(db *gorm.DB, model interface{}) *gorm.DB {
|
func (m *Mysql) AutoMigrateModel(model interface{}) error {
|
||||||
db.AutoMigrate(model)
|
err := m.gormConn.AutoMigrate(model)
|
||||||
db.Set("gorm:table_options", "CHARSET=utf8")
|
if err != nil {
|
||||||
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
return err
|
||||||
_ = db.Migrator().CreateTable(model)
|
}
|
||||||
return db.Model(model)
|
m.gormConn.Set("gorm:table_options", "CHARSET=utf8")
|
||||||
|
m.gormConn.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||||
|
_ = m.gormConn.Migrator().CreateTable(model)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Writer struct{}
|
type Writer struct{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user