From cfaa4c3285e7d57664900ba4c4e95728441c0b1c Mon Sep 17 00:00:00 2001 From: gutmet Date: Sun, 9 Dec 2018 11:40:26 +0100 Subject: [PATCH] provide command line application, print info about directory --- cmd/simpleserver.go | 15 +++++++++++++++ server.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 cmd/simpleserver.go diff --git a/cmd/simpleserver.go b/cmd/simpleserver.go new file mode 100644 index 0000000..30b84cd --- /dev/null +++ b/cmd/simpleserver.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "git.gutmet.org/simpleserver.git" + "os" +) + +func main() { + if len(os.Args) != 2 { + fmt.Println("Usage: " + os.Args[0] + " DIR") + os.Exit(1) + } + simpleserver.Serve(os.Args[1]) +} diff --git a/server.go b/server.go index 34cc9a9..5b200d2 100644 --- a/server.go +++ b/server.go @@ -26,7 +26,7 @@ func viewHandler(root string, w http.ResponseWriter, r *http.Request) { func Serve(root string) { address := "0.0.0.0:8000" - fmt.Println("Serving at http://" + address + " ...") + fmt.Println("Serving " + root + " at http://" + address + " ...") fmt.Println("Use Ctrl+C to exit") fmt.Println("(This is not a production web server, don't get any funny ideas)") http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { viewHandler(root, w, r) })