FindConfigFile searches for a config file in XDG-compliant locations
()
| 114 | |
| 115 | // FindConfigFile searches for a config file in XDG-compliant locations |
| 116 | func FindConfigFile() (string, error) { |
| 117 | searchPaths := []string{ |
| 118 | "lambda-nat-proxy.yaml", |
| 119 | "lambda-nat-proxy.yml", |
| 120 | filepath.Join(xdg.ConfigHome, "lambda-nat-proxy", "lambda-nat-proxy.yaml"), |
| 121 | filepath.Join(xdg.ConfigHome, "lambda-nat-proxy", "lambda-nat-proxy.yml"), |
| 122 | "/etc/lambda-nat-proxy/lambda-nat-proxy.yaml", |
| 123 | "/etc/lambda-nat-proxy/lambda-nat-proxy.yml", |
| 124 | } |
| 125 | |
| 126 | // Also check XDG config dirs |
| 127 | for _, dir := range xdg.ConfigDirs { |
| 128 | searchPaths = append(searchPaths, |
| 129 | filepath.Join(dir, "lambda-nat-proxy", "lambda-nat-proxy.yaml"), |
| 130 | filepath.Join(dir, "lambda-nat-proxy", "lambda-nat-proxy.yml"), |
| 131 | ) |
| 132 | } |
| 133 | |
| 134 | for _, path := range searchPaths { |
| 135 | if _, err := os.Stat(path); err == nil { |
| 136 | return path, nil |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return "", fmt.Errorf("no config file found in standard locations") |
| 141 | } |
| 142 | |
| 143 | // GetDefaultConfigPath returns the default path for creating a new config file |
| 144 | func GetDefaultConfigPath() string { |