@@ -154,6 +154,10 @@ func usage() {
154154 fmt .Fprintln (os .Stderr , " --port API server port (default: 6001)" )
155155 fmt .Fprintln (os .Stderr , " --frequency Pipeline update frequency (default: 5m)" )
156156 fmt .Fprintln (os .Stderr , " --no-server Run pipeline once and exit (no API server)" )
157+ fmt .Fprintln (os .Stderr , "TLS/HTTPS options:" )
158+ fmt .Fprintln (os .Stderr , " --tls-enable Enable TLS/HTTPS (default: false)" )
159+ fmt .Fprintln (os .Stderr , " --tls-cert TLS certificate file path" )
160+ fmt .Fprintln (os .Stderr , " --tls-key TLS private key file path" )
157161 fmt .Fprintln (os .Stderr , "Logging options:" )
158162 fmt .Fprintln (os .Stderr , " --log-level Logging level: debug, info, warn, error, fatal (default: info)" )
159163 fmt .Fprintln (os .Stderr , " --log-format Logging format: text or json (default: text)" )
@@ -194,6 +198,11 @@ func main() {
194198 freq := flag .Duration ("frequency" , 0 , "Pipeline update frequency (overrides config file)" )
195199 noServer := flag .Bool ("no-server" , false , "Run pipeline once and exit (no API server)" )
196200
201+ // TLS configuration
202+ tlsEnabled := flag .Bool ("tls-enable" , false , "Enable TLS/HTTPS (overrides config file)" )
203+ tlsCertFile := flag .String ("tls-cert" , "" , "TLS certificate file path (overrides config file)" )
204+ tlsKeyFile := flag .String ("tls-key" , "" , "TLS private key file path (overrides config file)" )
205+
197206 // Logging configuration
198207 logLevel := flag .String ("log-level" , "" , "Logging level (overrides config file)" )
199208 logFormat := flag .String ("log-format" , "" , "Logging format (overrides config file)" )
@@ -237,6 +246,15 @@ func main() {
237246 if * freq != 0 {
238247 cfg .Server .Frequency = * freq
239248 }
249+ if * tlsEnabled {
250+ cfg .Server .TLS .Enabled = * tlsEnabled
251+ }
252+ if * tlsCertFile != "" {
253+ cfg .Server .TLS .CertFile = * tlsCertFile
254+ }
255+ if * tlsKeyFile != "" {
256+ cfg .Server .TLS .KeyFile = * tlsKeyFile
257+ }
240258 if * logLevel != "" {
241259 cfg .Logging .Level = * logLevel
242260 }
@@ -352,17 +370,36 @@ func main() {
352370 listenAddr := fmt .Sprintf ("%s:%s" , cfg .Server .Host , cfg .Server .Port )
353371
354372 // Log startup information
373+ protocol := "HTTP"
374+ if cfg .Server .TLS .Enabled {
375+ protocol = "HTTPS"
376+ }
355377 logger .Info ("API server starting" ,
356378 logging .F ("address" , listenAddr ),
379+ logging .F ("protocol" , protocol ),
380+ logging .F ("tls_enabled" , cfg .Server .TLS .Enabled ),
357381 logging .F ("version" , Version ),
358382 logging .F ("pipeline" , pipelineFile ),
359383 logging .F ("log_level" , cfg .Logging .Level ),
360384 logging .F ("frequency" , cfg .Server .Frequency .String ()))
361385
362- if err := r .Run (listenAddr ); err != nil {
386+ // Start server with or without TLS based on configuration
387+ var serverErr error
388+ if cfg .Server .TLS .Enabled {
389+ logger .Info ("Starting HTTPS server" ,
390+ logging .F ("cert_file" , cfg .Server .TLS .CertFile ),
391+ logging .F ("key_file" , cfg .Server .TLS .KeyFile ))
392+ serverErr = r .RunTLS (listenAddr , cfg .Server .TLS .CertFile , cfg .Server .TLS .KeyFile )
393+ } else {
394+ logger .Info ("Starting HTTP server" )
395+ serverErr = r .Run (listenAddr )
396+ }
397+
398+ if serverErr != nil {
363399 logger .Error ("API server failed to start" ,
364- logging .F ("error" , err .Error ()),
365- logging .F ("address" , listenAddr ))
400+ logging .F ("error" , serverErr .Error ()),
401+ logging .F ("address" , listenAddr ),
402+ logging .F ("protocol" , protocol ))
366403 os .Exit (1 )
367404 }
368405}
0 commit comments