From 8bb2be248ddca4521510c4737412d49db07189fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Schr=C3=B6pfer?= Date: Wed, 3 Mar 2021 14:51:12 +0100 Subject: [PATCH] server port added --- cmd/server/main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 55c5d33..25d67d0 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" _ "embed" + "flag" "fmt" "io" "log" @@ -15,6 +16,10 @@ import ( //go:embed files/upload.htm var homepage []byte +var ( + flagPort = flag.String("p", ":2727", "port for the http-server") +) + func main() { run() } @@ -22,17 +27,16 @@ func main() { func run() { mux := http.NewServeMux() mux.HandleFunc("/convert/", handleConvert) - mux.HandleFunc("/test/", handleRoot) mux.HandleFunc("/", handleRoot) s := &http.Server{ - Addr: ":2727", + Addr: *flagPort, Handler: mux, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } fmt.Println("starting server at:") - fmt.Println("http://localhost:2727/") + fmt.Printf("http://localhost:%s/", *flagPort) log.Fatal(s.ListenAndServe()) }