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"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const usage = "servetls <cert file> <key file>"
|
||||
const port = 8443
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 3 {
|
||||
@ -18,6 +18,15 @@ func main() {
|
||||
|
||||
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)
|
||||
fmt.Printf("serving on %s", addr)
|
||||
err := http.ListenAndServeTLS(addr, cert, key, nil)
|
||||
|
Loading…
Reference in New Issue
Block a user