logging
This commit is contained in:
parent
bba06b2161
commit
a1e1413919
17
main.go
17
main.go
@ -1,9 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.milar.in/milarin/adverr"
|
"git.milar.in/milarin/adverr"
|
||||||
@ -22,11 +23,21 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
adverr.Fatalln(err, 1)
|
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)
|
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 {
|
if err := http.ListenAndServe(connStr, handler); err != nil {
|
||||||
adverr.Fatalln(err, 1)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user