MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / New

Function New

internal/config/config.go:106–152  ·  view source on GitHub ↗

New creates a new configuration with defaults from environment variables

()

Source from the content-addressed store, hash-verified

104
105// New creates a new configuration with defaults from environment variables
106func New() *Config {
107 // Determine performance mode from environment
108 modeStr := os.Getenv("MODE")
109 if modeStr == "" {
110 modeStr = "normal" // Default to normal mode
111 }
112
113 mode := PerformanceMode(modeStr)
114 modeConfigs := GetModeConfigs()
115
116 // Validate mode
117 modeConfig, exists := modeConfigs[mode]
118 if !exists {
119 log.Printf("⚠️ Invalid mode '%s', using 'normal' mode", modeStr)
120 mode = ModeNormal
121 modeConfig = modeConfigs[ModeNormal]
122 }
123
124 log.Printf("🚀 %s: %s", modeConfig.Name, getModeDescription(mode))
125
126 config := &Config{
127 // Set defaults
128 AWSRegion: shared.DefaultAWSRegion,
129 STUNServer: shared.DefaultSTUNServer,
130 SOCKS5Port: shared.DefaultSOCKS5Port,
131 LambdaResponseTimeout: shared.DefaultLambdaResponseTimeout,
132 NATHolePunchTimeout: shared.DefaultNATHolePunchTimeout,
133
134 // Apply mode configuration
135 Mode: mode,
136 ModeConfig: modeConfig,
137 Rotation: RotationConfig{
138 OverlapWindow: modeConfig.OverlapWindow,
139 DrainTimeout: modeConfig.DrainTimeout,
140 SessionTTL: modeConfig.SessionTTL,
141 },
142 }
143
144 // Override with environment variables
145 config.S3BucketName = os.Getenv("AWS_S3_BUCKET")
146
147 if region := os.Getenv("AWS_REGION"); region != "" {
148 config.AWSRegion = region
149 }
150
151 return config
152}
153
154// getModeDescription returns a description for the given mode
155func getModeDescription(mode PerformanceMode) string {

Callers 1

TestRotationDefaultsFunction · 0.70

Calls 3

PerformanceModeTypeAlias · 0.85
GetModeConfigsFunction · 0.85
getModeDescriptionFunction · 0.85

Tested by 1

TestRotationDefaultsFunction · 0.56