package zhub import ( "fmt" "os" "path/filepath" ) // InitFromCurrentDir 从当前目录的配置文件初始化 func InitFromCurrentDir() error { // 尝试多个可能的配置文件 possibleConfigs := []string{ "app.yml", "config.yml", "config.yaml", "app.yaml", "./conf/app.yml", "./config/app.yml", } for _, configPath := range possibleConfigs { if _, err := os.Stat(configPath); err == nil { return InitWithProjectConfig(configPath) } } return fmt.Errorf("no config file found in current directory") } // InitFromEnv 从环境变量指定的配置文件初始化 func InitFromEnv() error { configPath := os.Getenv("ZHUB_CONFIG_PATH") if configPath == "" { return fmt.Errorf("ZHUB_CONFIG_PATH environment variable not set") } return InitWithProjectConfig(configPath) } // InitWithWorkingDir 使用工作目录下的配置文件 func InitWithWorkingDir(configName string) error { if configName == "" { configName = "app.yml" } workDir, err := os.Getwd() if err != nil { return fmt.Errorf("failed to get working directory: %w", err) } configPath := filepath.Join(workDir, configName) return InitWithProjectConfig(configPath) }