Support listening for SSL connections

This commit is contained in:
Dane Everitt 2019-06-29 15:41:44 -07:00
parent 2db705f697
commit aa710ec9d6
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -91,11 +91,19 @@ func main() {
} }
router := r.ConfigureRouter() router := r.ConfigureRouter()
zap.S().Infow("configuring webserver", zap.String("host", c.Api.Host), zap.Int("port", c.Api.Port)) zap.S().Infow("configuring webserver", zap.Bool("ssl", c.Api.Ssl.Enabled), zap.String("host", c.Api.Host), zap.Int("port", c.Api.Port))
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", c.Api.Host, c.Api.Port), router); err != nil {
addr := fmt.Sprintf("%s:%d", c.Api.Host, c.Api.Port)
if c.Api.Ssl.Enabled {
if err := http.ListenAndServeTLS(addr, c.Api.Ssl.CertificateFile, c.Api.Ssl.KeyFile, router); err != nil {
zap.S().Fatalw("failed to configure HTTPS server", zap.Error(err))
}
} else {
if err := http.ListenAndServe(addr, router); err != nil {
zap.S().Fatalw("failed to configure HTTP server", zap.Error(err)) zap.S().Fatalw("failed to configure HTTP server", zap.Error(err))
} }
} }
}
// Configures the global logger for Zap so that we can call it from any location // Configures the global logger for Zap so that we can call it from any location
// in the code without having to pass around a logger instance. // in the code without having to pass around a logger instance.