forked from TrueCloudLab/frostfs-http-gw
app: add support for TLS key/cert options
Run in TLS mode if anything is specified.
This commit is contained in:
parent
a6f63c2bac
commit
491ae13190
3 changed files with 20 additions and 3 deletions
13
app.go
13
app.go
|
@ -178,9 +178,18 @@ func (a *app) Serve(ctx context.Context) {
|
|||
attachProfiler(r)
|
||||
}
|
||||
bind := a.cfg.GetString(cfgListenAddress)
|
||||
a.log.Info("running web server", zap.String("address", bind))
|
||||
tlsCertPath := a.cfg.GetString(cfgTLSCertificate)
|
||||
tlsKeyPath := a.cfg.GetString(cfgTLSKey)
|
||||
|
||||
a.webServer.Handler = r.Handler
|
||||
if err := a.webServer.ListenAndServe(bind); err != nil {
|
||||
if tlsCertPath == "" && tlsKeyPath == "" {
|
||||
a.log.Info("running web server", zap.String("address", bind))
|
||||
err = a.webServer.ListenAndServe(bind)
|
||||
} else {
|
||||
a.log.Info("running web server (TLS-enabled)", zap.String("address", bind))
|
||||
err = a.webServer.ListenAndServeTLS(bind, tlsCertPath, tlsKeyPath)
|
||||
}
|
||||
if err != nil {
|
||||
a.log.Fatal("could not start server", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue