Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 6ba057a

Browse files
author
Audrius Karabanovas
authored
Merge pull request #38 from prezi/tls_support
Adding TLS support
2 parents fa0f26f + e286db5 commit 6ba057a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

main.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func main() {
3030
var (
3131
Name = serviceName
3232
listenAddress = flag.String("web.listen-address", ":9479", "Address to listen on for web interface and telemetry.")
33+
tlsCertFile = flag.String("tls.certfile", "", "TLS certs file if you want to use tls instead of http")
34+
tlsKeyFile = flag.String("tls.keyfile", "", "TLS key file if you want to use tls instead of http")
3335
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
3436
beatURI = flag.String("beat.uri", "http://localhost:5066", "HTTP API address of beat.")
3537
beatTimeout = flag.Duration("beat.timeout", 10*time.Second, "Timeout for trying to get stats from beat.")
@@ -134,12 +136,22 @@ beatdiscovery:
134136
}()
135137

136138
log.Info("Starting listener")
137-
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
139+
if *tlsCertFile != "" && *tlsKeyFile != "" {
140+
if err := http.ListenAndServeTLS(*listenAddress, *tlsCertFile, *tlsKeyFile, nil); err != nil {
138141

139-
log.WithFields(log.Fields{
140-
"err": err,
141-
}).Errorf("http server quit with error: %v", err)
142+
log.WithFields(log.Fields{
143+
"err": err,
144+
}).Errorf("tls server quit with error: %v", err)
142145

146+
}
147+
} else {
148+
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
149+
150+
log.WithFields(log.Fields{
151+
"err": err,
152+
}).Errorf("http server quit with error: %v", err)
153+
154+
}
143155
}
144156
log.Info("Listener exited")
145157
}()

0 commit comments

Comments
 (0)