LoadDefault 从默认位置加载配置 查找顺序: 1. ./agent.yaml 2. ./config/agent.yaml 3. ~/.aster/agent.yaml
()
| 348 | // 2. ./config/agent.yaml |
| 349 | // 3. ~/.aster/agent.yaml |
| 350 | func LoadDefault() (*types.AgentConfig, error) { |
| 351 | loader := NewLoader() |
| 352 | |
| 353 | paths := []string{ |
| 354 | "agent.yaml", |
| 355 | "agent.yml", |
| 356 | "config/agent.yaml", |
| 357 | "config/agent.yml", |
| 358 | } |
| 359 | |
| 360 | // 添加用户目录 |
| 361 | if home, err := os.UserHomeDir(); err == nil { |
| 362 | paths = append(paths, home+"/.aster/agent.yaml") |
| 363 | paths = append(paths, home+"/.aster/agent.yml") |
| 364 | } |
| 365 | |
| 366 | for _, path := range paths { |
| 367 | if _, err := os.Stat(path); err == nil { |
| 368 | return loader.LoadAgentConfig(path) |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | return nil, fmt.Errorf("no default config file found in: %v", paths) |
| 373 | } |
| 374 | |
| 375 | // MustLoad 必须成功加载配置,否则 panic |
| 376 | func MustLoad(path string) *types.AgentConfig { |
nothing calls this directly
no test coverage detected