added ability to specify port via env
This commit is contained in:
parent
08cd989b00
commit
346b7ecd32
11
main.go
11
main.go
@ -4,10 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const usage = "servetls <cert file> <key file>"
|
const usage = "servetls <cert file> <key file>"
|
||||||
const port = 8443
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) != 3 {
|
if len(os.Args) != 3 {
|
||||||
@ -18,6 +18,15 @@ func main() {
|
|||||||
|
|
||||||
http.HandleFunc("/", handler)
|
http.HandleFunc("/", handler)
|
||||||
|
|
||||||
|
port := 8443
|
||||||
|
if os.Getenv("PORT") != "" {
|
||||||
|
p, err := strconv.Atoi(os.Getenv("PORT"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "could not parse PORT variable: %s\n", os.Getenv("PORT"))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
port = p
|
||||||
|
}
|
||||||
addr := fmt.Sprintf(":%d", port)
|
addr := fmt.Sprintf(":%d", port)
|
||||||
fmt.Printf("serving on %s", addr)
|
fmt.Printf("serving on %s", addr)
|
||||||
err := http.ListenAndServeTLS(addr, cert, key, nil)
|
err := http.ListenAndServeTLS(addr, cert, key, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user