parent
6704fc8302
commit
36cf5eee3e
|
|
@ -10,6 +10,7 @@ package main
|
|||
|
||||
import (
|
||||
"local/args"
|
||||
"local/gziphttp"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
|
@ -26,9 +27,21 @@ func main() {
|
|||
d := fs.Get("d").GetString()
|
||||
p := strings.TrimPrefix(fs.Get("p").GetString(), ":")
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(d)))
|
||||
http.Handle("/", http.HandlerFunc(handler(d)))
|
||||
|
||||
log.Printf("Serving %s on HTTP port: %s\n", d, p)
|
||||
|
||||
log.Fatal(http.ListenAndServe(":"+p, nil))
|
||||
}
|
||||
|
||||
func handler(d string) func(http.ResponseWriter, *http.Request) {
|
||||
h := http.FileServer(http.Dir(d))
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if gziphttp.Can(r) {
|
||||
gz := gziphttp.New(w)
|
||||
defer gz.Close()
|
||||
w = gz
|
||||
}
|
||||
h.ServeHTTP(w, r)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
hi
|
||||
Loading…
Reference in New Issue