parent
6704fc8302
commit
36cf5eee3e
|
|
@ -10,6 +10,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"local/args"
|
"local/args"
|
||||||
|
"local/gziphttp"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -26,9 +27,21 @@ func main() {
|
||||||
d := fs.Get("d").GetString()
|
d := fs.Get("d").GetString()
|
||||||
p := strings.TrimPrefix(fs.Get("p").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.Printf("Serving %s on HTTP port: %s\n", d, p)
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":"+p, nil))
|
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