From 30b464449c065eeb5268854db68ac350f647ecc1 Mon Sep 17 00:00:00 2001 From: Akilan Date: Fri, 25 Apr 2025 23:50:56 +0100 Subject: [PATCH] added basic static server --- Docs/staticServer.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Docs/staticServer.go diff --git a/Docs/staticServer.go b/Docs/staticServer.go new file mode 100644 index 0000000..c88ae4a --- /dev/null +++ b/Docs/staticServer.go @@ -0,0 +1,28 @@ +/* +Serve is a very simple static file server in go +Usage: + + -p="8100": port to serve on + -d=".": the directory of static files to host + +Navigating to http://localhost:8100 will display the index.html or directory +listing file. +*/ +package main + +import ( + "flag" + "log" + "net/http" +) + +func main() { + port := flag.String("p", "8100", "port to serve on") + directory := flag.String("d", ".", "the directory of static file to host") + flag.Parse() + + http.Handle("/", http.FileServer(http.Dir(*directory))) + + log.Printf("Serving %s on HTTP port: %s\n", *directory, *port) + log.Fatal(http.ListenAndServe(":"+*port, nil)) +}