Skip to content

Commit d2c7a40

Browse files
committed
configurable port
1 parent 1285854 commit d2c7a40

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docker-cloud/main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@ import (
44
"fmt"
55
"log"
66
"net/http"
7+
"os"
78
)
89

910
type Config struct {
10-
Port int
11+
Port string
1112
}
1213

1314
func main() {
15+
port := os.Getenv("HTTP_PORT")
16+
if port == "" {
17+
port = "8080"
18+
}
19+
1420
config := Config{
15-
Port: 8080,
21+
Port: port,
1622
}
1723

1824
http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
1925
w.Write([]byte("pong"))
2026
})
2127

22-
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", config.Port), nil))
28+
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", config.Port), nil))
2329
}

0 commit comments

Comments
 (0)