Skip to content

Commit ebac727

Browse files
committed
chore(golang): respect PORT env variable
Part of #9
1 parent 62f8d76 commit ebac727

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

examples/go/app.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ func main() {
99
r := chi.NewRouter()
1010
registerRoutes(r)
1111

12-
fmt.Println("Listen on 3000")
13-
err := http.ListenAndServe(":3000", r)
12+
port := os.Getenv("PORT")
13+
if port == "" {
14+
port = "3000"
15+
}
16+
17+
fmt.Println("Listen on " + port)
18+
err := http.ListenAndServe(":"+port, r)
1419
fmt.Fprintf(os.Stderr, "ListenAndServe failed: %v\n", err)
1520
os.Exit(1)
1621
}

src/templates/app.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ func main() {
99
r := chi.NewRouter()
1010
registerRoutes(r)
1111

12-
fmt.Println("Listen on 3000")
13-
err := http.ListenAndServe(":3000", r)
12+
port := os.Getenv("PORT")
13+
if port == "" {
14+
port = "3000"
15+
}
16+
17+
fmt.Println("Listen on " + port)
18+
err := http.ListenAndServe(":"+port, r)
1419
fmt.Fprintf(os.Stderr, "ListenAndServe failed: %v\n", err)
1520
os.Exit(1)
1621
}

0 commit comments

Comments
 (0)