feat(auth): 完成租户用户角色资源核心模块
This commit is contained in:
@@ -28,6 +28,7 @@ type DatabaseConfig struct {
|
||||
Password string
|
||||
DBName string
|
||||
SSLMode string
|
||||
Driver string // mysql, postgres
|
||||
}
|
||||
|
||||
type RedisConfig struct {
|
||||
@@ -43,11 +44,11 @@ type JWTConfig struct {
|
||||
}
|
||||
|
||||
type AIConfig struct {
|
||||
Provider string
|
||||
APIKey string
|
||||
Model string
|
||||
BaseURL string
|
||||
MaxTokens int
|
||||
Provider string
|
||||
APIKey string
|
||||
Model string
|
||||
BaseURL string
|
||||
MaxTokens int
|
||||
Temperature float64
|
||||
}
|
||||
|
||||
@@ -56,6 +57,7 @@ type WebSocketConfig struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
// Load 加载配置文件
|
||||
func Load() (*Config, error) {
|
||||
return &Config{
|
||||
Server: ServerConfig{
|
||||
@@ -65,12 +67,13 @@ func Load() (*Config, error) {
|
||||
WriteTimeout: getEnvAsInt("SERVER_WRITE_TIMEOUT", 30),
|
||||
},
|
||||
Database: DatabaseConfig{
|
||||
Host: getEnv("DB_HOST", "localhost"),
|
||||
Port: getEnvAsInt("DB_PORT", 5432),
|
||||
User: getEnv("DB_USER", "postgres"),
|
||||
Password: getEnv("DB_PASSWORD", "postgres"),
|
||||
DBName: getEnv("DB_NAME", "customer_service"),
|
||||
SSLMode: getEnv("DB_SSL_MODE", "disable"),
|
||||
Host: getEnv("DB_HOST", "124.221.239.98"),
|
||||
Port: getEnvAsInt("DB_PORT", 3306),
|
||||
User: getEnv("DB_USER", "root"),
|
||||
Password: getEnv("DB_PASSWORD", "machine03"),
|
||||
DBName: getEnv("DB_NAME", "openclaw"),
|
||||
SSLMode: getEnv("DB_SSL_MODE", "TRUE"),
|
||||
Driver: getEnv("DB_DRIVER", "mysql"),
|
||||
},
|
||||
Redis: RedisConfig{
|
||||
Host: getEnv("REDIS_HOST", "localhost"),
|
||||
@@ -83,11 +86,11 @@ func Load() (*Config, error) {
|
||||
Expiration: getEnvAsInt("JWT_EXPIRATION", 86400),
|
||||
},
|
||||
AI: AIConfig{
|
||||
Provider: getEnv("AI_PROVIDER", "openai"),
|
||||
APIKey: getEnv("AI_API_KEY", ""),
|
||||
Model: getEnv("AI_MODEL", "gpt-3.5-turbo"),
|
||||
BaseURL: getEnv("AI_BASE_URL", "https://api.openai.com/v1"),
|
||||
MaxTokens: getEnvAsInt("AI_MAX_TOKENS", 1000),
|
||||
Provider: getEnv("AI_PROVIDER", "openai"),
|
||||
APIKey: getEnv("AI_API_KEY", ""),
|
||||
Model: getEnv("AI_MODEL", "gpt-3.5-turbo"),
|
||||
BaseURL: getEnv("AI_BASE_URL", "https://api.openai.com/v1"),
|
||||
MaxTokens: getEnvAsInt("AI_MAX_TOKENS", 1000),
|
||||
Temperature: getEnvAsFloat("AI_TEMPERATURE", 0.7),
|
||||
},
|
||||
WebSocket: WebSocketConfig{
|
||||
@@ -97,15 +100,26 @@ func Load() (*Config, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetDSN 返回数据库连接字符串
|
||||
func (c *Config) GetDSN() string {
|
||||
dbConfig := c.Database
|
||||
if dbConfig.Driver == "mysql" {
|
||||
return dbConfig.User + ":" + dbConfig.Password + "@tcp(" +
|
||||
dbConfig.Host + ":" + strconv.Itoa(dbConfig.Port) + ")/" +
|
||||
dbConfig.DBName + "?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
}
|
||||
return "" // PostgreSQL 暂未实现
|
||||
}
|
||||
|
||||
func getEnv(key, defaultValue string) string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
if value, exists := os.LookupEnv(key); exists {
|
||||
return value
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func getEnvAsInt(key string, defaultValue int) int {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
if value, exists := os.LookupEnv(key); exists {
|
||||
if intValue, err := strconv.Atoi(value); err == nil {
|
||||
return intValue
|
||||
}
|
||||
@@ -114,7 +128,7 @@ func getEnvAsInt(key string, defaultValue int) int {
|
||||
}
|
||||
|
||||
func getEnvAsFloat(key string, defaultValue float64) float64 {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
if value, exists := os.LookupEnv(key); exists {
|
||||
if floatValue, err := strconv.ParseFloat(value, 64); err == nil {
|
||||
return floatValue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user