master v0.1
Bel LaPointe 2020-02-14 08:24:35 -07:00
parent 6704fc8302
commit 36cf5eee3e
3 changed files with 15 additions and 1 deletions

0
.gitignore vendored Normal file → Executable file
View File

15
main.go Normal file → Executable file
View File

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

1
public/_index.html Executable file
View File

@ -0,0 +1 @@
hi