From a26f3aa21f89d6e4606ecd8af148b41feb4971ea Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Wed, 26 Sep 2018 08:50:15 -0600 Subject: [PATCH] neat --- .gitignore | 10 ++++++++++ main.go | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .gitignore create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b402e50 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.key +*.crt +*.pem +*.swp +*.swo +*.pub +cli-keys +fake-ssh +gcpkeys +*.json diff --git a/main.go b/main.go new file mode 100644 index 0000000..495c3b9 --- /dev/null +++ b/main.go @@ -0,0 +1,26 @@ +/* +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)) +}