aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2020-03-26 21:18:30 +0000
committerGrégoire Duchêne <gduchene@awhk.org>2020-03-26 21:18:30 +0000
commit0d32b71317472ab5d93aa98f8db02609ed1318bc (patch)
tree2c641f5d4e81d177db4d23867d36c83fd1d7c277
parent0ea3c6452a7a93e8a228aa522f356aaa604bc478 (diff)
Allow listening on a specific address
The address is read from the ADDR environment variable. Defaults to every address.
-rw-r--r--README.md8
-rw-r--r--gcp/main.go2
2 files changed, 7 insertions, 3 deletions
diff --git a/README.md b/README.md
index 1fe7219..ca9464e 100644
--- a/README.md
+++ b/README.md
@@ -11,5 +11,9 @@ You need to set up the following environment variables for it to work:
e.g. `golang.org/x/` for `golang.org/x/image`, and
* `VCS` for the type of VCS you are using, e.g. `git`.
-Additionally, the version under `gcp/` will bind to the port passed in
-the `PORT` environment variable, or 8080 if that variable is not set.
+Additionally, the version under `gcp/` will use:
+
+* `ADDR` for the address to listen on, defaulting to every address, and
+* `PORT` for the port to listen on, defaulting to 8080.
+
+See https://golang.org/pkg/net/#Dial for details of the address format.
diff --git a/gcp/main.go b/gcp/main.go
index c5c8466..bb792cc 100644
--- a/gcp/main.go
+++ b/gcp/main.go
@@ -31,5 +31,5 @@ func main() {
port = "8080"
}
http.HandleFunc("/", redirect)
- log.Fatal(http.ListenAndServe(":"+port, nil))
+ log.Fatal(http.ListenAndServe(os.Getenv("ADDR")+":"+port, nil))
}