1
0
Fork 0
mirror of https://github.com/vbatts/freezing-octo-hipster.git synced 2024-12-23 04:06:31 +00:00
random-utils/cmd/fsrv/main.go
Vincent Batts 0d414be0e7
fsrv: simple file server
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-08-29 14:28:11 -04:00

29 lines
621 B
Go

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