MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / LoadDefault

Function LoadDefault

cmd/gosqlx/internal/config/config.go:277–308  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

275// // cfg is always non-nil, even if err != nil
276// // err indicates which config was loaded or if defaults were used
277func 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
311func (c *Config) Save(path string) error {

Callers 14

validateRunFunction · 0.92
validateFromStdinFunction · 0.92
analyzeRunFunction · 0.92
analyzeFromStdinFunction · 0.92
formatRunFunction · 0.92
formatFromStdinFunction · 0.92
formatInlineSQLFunction · 0.92
parseRunFunction · 0.92
parseFromStdinFunction · 0.92
ValidateMethod · 0.92
ShowMethod · 0.92

Calls 2

LoadFunction · 0.85
DefaultConfigFunction · 0.70

Tested by 3

TestConfigPrecedenceFunction · 0.68