Skip to content

Commit 070c88b

Browse files
graysideknative-prow-robot
authored andcommitted
serving/helloworld-go: Respect the PORT env var (#457)
1 parent 421f44e commit 070c88b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

serving/samples/helloworld-go/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ following instructions recreate the source files from this folder.
4242
}
4343

4444
func main() {
45-
flag.Parse()
4645
log.Print("Hello world sample started.")
4746

4847
http.HandleFunc("/", handler)
49-
http.ListenAndServe(":8080", nil)
48+
49+
port := os.Getenv("PORT")
50+
if port == "" {
51+
port = "8080"
52+
}
53+
54+
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
5055
}
5156
```
5257

serving/samples/helloworld-go/helloworld.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@ func main() {
3636
log.Print("Hello world sample started.")
3737

3838
http.HandleFunc("/", handler)
39-
http.ListenAndServe(":8080", nil)
39+
40+
port := os.Getenv("PORT")
41+
if port == "" {
42+
port = "8080"
43+
}
44+
45+
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
4046
}

0 commit comments

Comments
 (0)