mirror of
https://github.com/vbatts/freezing-octo-hipster.git
synced 2024-11-22 15:05:39 +00:00
fsrv: simple file server
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
d8b23b86fa
commit
0d414be0e7
2 changed files with 40 additions and 0 deletions
11
cmd/fsrv/README.md
Normal file
11
cmd/fsrv/README.md
Normal 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
29
cmd/fsrv/main.go
Normal 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))
|
||||||
|
}
|
Loading…
Reference in a new issue