configurable listen address

This commit is contained in:
Stefan Schwarz 2020-12-28 02:39:08 +01:00
parent 4f41e275d6
commit 7492095dd1
1 changed files with 5 additions and 1 deletions

View File

@ -22,6 +22,10 @@ func main() {
if !ok { if !ok {
log.Fatalf("unable to read CONTAINER_NAME") log.Fatalf("unable to read CONTAINER_NAME")
} }
listen, ok := os.LookupEnv("LISTEN")
if !ok {
listen = ":8080"
}
defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"} defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"}
cli, err := client.NewClient("unix:///var/run/docker.sock", "v1.44", nil, defaultHeaders) cli, err := client.NewClient("unix:///var/run/docker.sock", "v1.44", nil, defaultHeaders)
@ -38,7 +42,7 @@ func main() {
go counter.Scan(logs) go counter.Scan(logs)
http.HandleFunc("/", counter.MetricsHandler) http.HandleFunc("/", counter.MetricsHandler)
err = http.ListenAndServe(":8080", nil) err = http.ListenAndServe(listen, nil)
log.Fatalf("unable to listen: %s", err) log.Fatalf("unable to listen: %s", err)
} }