LoadDefault tries to load configuration from standard locations with precedence. This function searches for configuration files in multiple standard locations and loads the first one found. If no configuration file exists, it returns a default configuration. Search order (first found wins): 1. Cur
()
| 275 | // // cfg is always non-nil, even if err != nil |
| 276 | // // err indicates which config was loaded or if defaults were used |
| 277 | func LoadDefault() (*Config, error) { |
| 278 | searchPaths := []string{ |
| 279 | ".gosqlx.yml", |
| 280 | "~/.gosqlx.yml", |
| 281 | "/etc/gosqlx.yml", |
| 282 | } |
| 283 | |
| 284 | for _, path := range searchPaths { |
| 285 | // Expand home directory |
| 286 | expandedPath := path |
| 287 | if len(path) > 0 && path[0] == '~' { |
| 288 | home, err := os.UserHomeDir() |
| 289 | if err != nil { |
| 290 | continue |
| 291 | } |
| 292 | expandedPath = filepath.Join(home, path[1:]) |
| 293 | } |
| 294 | |
| 295 | // Check if file exists |
| 296 | if _, err := os.Stat(expandedPath); err == nil { |
| 297 | config, err := Load(expandedPath) |
| 298 | if err != nil { |
| 299 | // Log error but continue searching |
| 300 | continue |
| 301 | } |
| 302 | return config, nil |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | // No config file found, return defaults |
| 307 | return DefaultConfig(), nil |
| 308 | } |
| 309 | |
| 310 | // Save writes the configuration to the specified path |
| 311 | func (c *Config) Save(path string) error { |