WriteExampleConfig creates an example configuration file
(filePath string)
| 79 | |
| 80 | // WriteExampleConfig creates an example configuration file |
| 81 | func WriteExampleConfig(filePath string) error { |
| 82 | exampleConfig := `# Lambda NAT Proxy Configuration File |
| 83 | # This file contains all available configuration options with their default values |
| 84 | |
| 85 | # AWS Configuration |
| 86 | aws: |
| 87 | region: "us-west-2" # AWS region to use |
| 88 | profile: "" # AWS profile (leave empty for default credential chain) |
| 89 | |
| 90 | # Deployment Configuration |
| 91 | deployment: |
| 92 | stack_name: "lambda-nat-proxy-a1b2c3d4" # CloudFormation stack name (unique suffix auto-generated) |
| 93 | mode: "normal" # Performance mode: test, normal, performance |
| 94 | |
| 95 | # Proxy Configuration |
| 96 | proxy: |
| 97 | port: 1080 # SOCKS5 proxy port (standard SOCKS port) |
| 98 | stun_server: "stun.l.google.com:19302" # STUN server for NAT traversal |
| 99 | ` |
| 100 | |
| 101 | // Create directory if it doesn't exist |
| 102 | dir := filepath.Dir(filePath) |
| 103 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 104 | return fmt.Errorf("failed to create directory %s: %w", dir, err) |
| 105 | } |
| 106 | |
| 107 | // Write the example config |
| 108 | if err := os.WriteFile(filePath, []byte(exampleConfig), 0644); err != nil { |
| 109 | return fmt.Errorf("failed to write config file %s: %w", filePath, err) |
| 110 | } |
| 111 | |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | // FindConfigFile searches for a config file in XDG-compliant locations |
| 116 | func FindConfigFile() (string, error) { |