fsrv: simple file server

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2017-08-29 14:28:11 -04:00
parent d8b23b86fa
commit 0d414be0e7
Signed by: vbatts
GPG key ID: 10937E57733F1362
2 changed files with 40 additions and 0 deletions

11
cmd/fsrv/README.md Normal file
View file

@ -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 ...
```

29
cmd/fsrv/main.go Normal file
View file

@ -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))
}