Skip to content

Commit

Permalink
Merge pull request #38 from prezi/tls_support
Browse files Browse the repository at this point in the history
Adding TLS support
  • Loading branch information
Audrius Karabanovas authored Jun 12, 2020
2 parents fa0f26f + e286db5 commit 6ba057a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func main() {
var (
Name = serviceName
listenAddress = flag.String("web.listen-address", ":9479", "Address to listen on for web interface and telemetry.")
tlsCertFile = flag.String("tls.certfile", "", "TLS certs file if you want to use tls instead of http")
tlsKeyFile = flag.String("tls.keyfile", "", "TLS key file if you want to use tls instead of http")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
beatURI = flag.String("beat.uri", "http://localhost:5066", "HTTP API address of beat.")
beatTimeout = flag.Duration("beat.timeout", 10*time.Second, "Timeout for trying to get stats from beat.")
Expand Down Expand Up @@ -134,12 +136,22 @@ beatdiscovery:
}()

log.Info("Starting listener")
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
if *tlsCertFile != "" && *tlsKeyFile != "" {
if err := http.ListenAndServeTLS(*listenAddress, *tlsCertFile, *tlsKeyFile, nil); err != nil {

log.WithFields(log.Fields{
"err": err,
}).Errorf("http server quit with error: %v", err)
log.WithFields(log.Fields{
"err": err,
}).Errorf("tls server quit with error: %v", err)

}
} else {
if err := http.ListenAndServe(*listenAddress, nil); err != nil {

log.WithFields(log.Fields{
"err": err,
}).Errorf("http server quit with error: %v", err)

}
}
log.Info("Listener exited")
}()
Expand Down

0 comments on commit 6ba057a

Please sign in to comment.