From 0d414be0e7c6e9d958fdd6c78d22ed91b38dfb60 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Tue, 29 Aug 2017 14:28:11 -0400 Subject: [PATCH] fsrv: simple file server Signed-off-by: Vincent Batts --- cmd/fsrv/README.md | 11 +++++++++++ cmd/fsrv/main.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 cmd/fsrv/README.md create mode 100644 cmd/fsrv/main.go diff --git a/cmd/fsrv/README.md b/cmd/fsrv/README.md new file mode 100644 index 0000000..509787f --- /dev/null +++ b/cmd/fsrv/README.md @@ -0,0 +1,11 @@ +# fsrv + +Dumb simple static file server. + +## Usage + +```shell +$> fsrv -root ./default.castr/ +2014/05/05 11:26:25 Serving /home/vbatts/default.castr on 127.0.0.1:8888 ... +``` + diff --git a/cmd/fsrv/main.go b/cmd/fsrv/main.go new file mode 100644 index 0000000..5287403 --- /dev/null +++ b/cmd/fsrv/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "flag" + "log" + "net/http" + "path/filepath" +) + +var ( + flRoot = flag.String("root", ".", "root path to serve") + //flPrefix = flag.String("prefix", "", "prefix the served URL path") + flBind = flag.String("b", "127.0.0.1", "addr to bind to") + flPort = flag.String("p", "8888", "port to listen on") +) + +func main() { + flag.Parse() + + var err error + *flRoot, err = filepath.Abs(*flRoot) + if err != nil { + log.Fatal(err) + } + + http.Handle("/", http.FileServer(http.Dir(*flRoot))) + log.Printf("Serving %s on %s:%s ...", *flRoot, *flBind, *flPort) + log.Fatal(http.ListenAndServe(*flBind+":"+*flPort, nil)) +}