Make the port number configurable
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
6b5592a10c
commit
763ad185a4
1 changed files with 19 additions and 1 deletions
|
@ -3,7 +3,9 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
@ -51,8 +53,24 @@ func getResponseCode(r *http.Request) int {
|
|||
return http.StatusOK
|
||||
}
|
||||
|
||||
func getPort() string {
|
||||
port := os.Getenv("PORT")
|
||||
|
||||
if port != "" {
|
||||
return port
|
||||
}
|
||||
|
||||
return "8080"
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", handler)
|
||||
|
||||
http.ListenAndServe(":8080", nil)
|
||||
addr := ":" + getPort()
|
||||
|
||||
fmt.Printf("Starting server on %s", addr)
|
||||
|
||||
if err := http.ListenAndServe(addr, nil); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue