This commit is contained in:
milarin 2023-02-10 10:11:02 +01:00
parent bba06b2161
commit a1e1413919

17
main.go
View File

@ -1,9 +1,10 @@
package main
import (
"net/http"
"flag"
"fmt"
"log"
"net/http"
"path/filepath"
"git.milar.in/milarin/adverr"
@ -22,11 +23,21 @@ func main() {
if err != nil {
adverr.Fatalln(err, 1)
}
*root = abspath
fmt.Printf("Root Directory: %s\nURL: http://%s:%d/\n", *root, *iface, *port)
fmt.Printf("Root Directory: %s\nURL: http://%s:%d/\n", abspath, *iface, *port)
connStr := fmt.Sprintf("%s:%d", *iface, *port)
handler := http.FileServer(http.Dir(*root))
handler := LogHandler(http.FileServer(http.Dir(*root)))
if err := http.ListenAndServe(connStr, handler); err != nil {
adverr.Fatalln(err, 1)
}
}
func LogHandler(handler http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s", r.Method, r.URL)
handler.ServeHTTP(w, r)
}
}