summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go29
1 files changed, 15 insertions, 14 deletions
diff --git a/main.go b/main.go
index 9ec7157..452ed35 100644
--- a/main.go
+++ b/main.go
@@ -10,24 +10,20 @@ import (
"strings"
)
-func accessLog(h http.Handler) http.Handler {
+func accessLog(h http.Handler, quiet bool) http.Handler {
t := &TemplateHandler{handler: h}
- //t := &TemplateHandler{}
fn := func(w http.ResponseWriter, r *http.Request) {
- log.Println(r.Method, r.URL.Path, r.RemoteAddr)
+ if !quiet {
+ log.Println(r.Method, r.URL.Path, r.RemoteAddr)
+ }
t.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
-/*
-func TemplateHandler(h http.Handler) http.Handler {
- h.handler
-}
-*/
-
-func uploadHandler(dir string) http.Handler {
+func uploadHandler(dir string, quiet bool) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Server", "uhttpd")
file, header, err := r.FormFile("file")
if err != nil {
@@ -60,7 +56,9 @@ func uploadHandler(dir string) http.Handler {
return
}
- log.Println(r.Method, r.URL.Path, header.Filename, r.RemoteAddr)
+ if !quiet {
+ log.Println(r.Method, r.URL.Path, header.Filename, r.RemoteAddr)
+ }
w.Write([]byte("Uploaded " + header.Filename))
}
return http.HandlerFunc(fn)
@@ -72,6 +70,7 @@ func main() {
dir_f := flag.String("dir", ".", "Directory to serve.")
disallow_upl_f := flag.Bool("disallow-upload", false, "Disallow uploads to /upload.")
upl_dir_f := flag.String("upload-dir", ".", "Directory to store uploaded files.")
+ quiet_f := flag.Bool("quiet", false, "Be quiet, suppress output.")
flag.Parse()
@@ -80,13 +79,15 @@ func main() {
port = *port_f
}
- fmt.Println("Starting uhttpd serving \"" + *dir_f + "\" on " + *ip_f + ":" + port + ".")
+ if !*quiet_f {
+ fmt.Println("Starting uhttpd serving \"" + *dir_f + "\" on " + *ip_f + ":" + port + ".")
+ }
mux := http.NewServeMux()
if !*disallow_upl_f {
os.MkdirAll(*upl_dir_f, 0755)
- mux.Handle("/upload", uploadHandler(*upl_dir_f))
+ mux.Handle("/upload", uploadHandler(*upl_dir_f, *quiet_f))
}
- mux.Handle("/", accessLog(http.FileServer(http.Dir(*dir_f))))
+ mux.Handle("/", accessLog(http.FileServer(http.Dir(*dir_f)), *quiet_f))
log.Fatal(http.ListenAndServe(*ip_f+":"+port, mux))
}