42 lines
738 B
Go
42 lines
738 B
Go
package common
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"server/config"
|
|
)
|
|
|
|
// TenantHeaderKey 获取租户Header字段名
|
|
func TenantHeaderKey() string {
|
|
headerKey := strings.TrimSpace(config.AppConfig.Tenant.HeaderKey)
|
|
if headerKey == "" {
|
|
return "X-Tenant-Id"
|
|
}
|
|
return headerKey
|
|
}
|
|
|
|
// IsTenantTable 判断表是否启用租户过滤
|
|
func IsTenantTable(table string) bool {
|
|
cfg := config.AppConfig.Tenant
|
|
if !cfg.Enable {
|
|
return false
|
|
}
|
|
name := normalizeTableName(table)
|
|
if name == "" {
|
|
return false
|
|
}
|
|
for _, item := range cfg.Tables {
|
|
tableName := normalizeTableName(item)
|
|
if tableName == "" {
|
|
continue
|
|
}
|
|
if tableName == "*" {
|
|
return true
|
|
}
|
|
if strings.EqualFold(tableName, name) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|