feat: add im kafka admin integration
This commit is contained in:
@@ -21,6 +21,8 @@ var tenantDbGroups sync.Map
|
||||
|
||||
const registryDbGroup = "imRegistry"
|
||||
|
||||
var registryDbGroupOnce sync.Once
|
||||
|
||||
// DB resolves a tenant registry record and returns the corresponding business DB.
|
||||
func DB(ctx context.Context, tenantId int64) (db gdb.DB, tenant *entity.ImTenant, err error) {
|
||||
if tenantId <= 0 {
|
||||
@@ -60,12 +62,34 @@ func DB(ctx context.Context, tenantId int64) (db gdb.DB, tenant *entity.ImTenant
|
||||
// RegistryDB returns the dedicated tenant registry connection, or the default
|
||||
// HotGo database when a separate registry group is not configured.
|
||||
func RegistryDB() gdb.DB {
|
||||
registryDbGroupOnce.Do(func() {
|
||||
ensureRegistryDBGroup()
|
||||
})
|
||||
if configs, err := gdb.GetConfigGroup(registryDbGroup); err == nil && len(configs) > 0 {
|
||||
return g.DB(registryDbGroup)
|
||||
}
|
||||
return g.DB()
|
||||
}
|
||||
|
||||
func ensureRegistryDBGroup() {
|
||||
if configs, err := gdb.GetConfigGroup(registryDbGroup); err == nil && len(configs) > 0 {
|
||||
configs[0].Prefix = ""
|
||||
_ = gdb.SetConfigGroup(registryDbGroup, configs)
|
||||
return
|
||||
}
|
||||
|
||||
configs, err := gdb.GetConfigGroup("default")
|
||||
if err != nil || len(configs) == 0 {
|
||||
return
|
||||
}
|
||||
cloned := make(gdb.ConfigGroup, len(configs))
|
||||
copy(cloned, configs)
|
||||
for i := range cloned {
|
||||
cloned[i].Prefix = ""
|
||||
}
|
||||
_ = gdb.SetConfigGroup(registryDbGroup, cloned)
|
||||
}
|
||||
|
||||
func tenantLink(ctx context.Context, tenant *entity.ImTenant) (string, error) {
|
||||
if tenant.DbDsn != "" {
|
||||
return normalizeMySQLTimeOptions(tenant.DbDsn)
|
||||
|
||||
Reference in New Issue
Block a user