99 "net/http/httputil"
1010)
1111
12+ // Options passed via CLI
1213type Options struct {
1314 ListenAddress string
1415 Folder string
@@ -32,6 +33,7 @@ func main() {
3233 fmt .Println (http .ListenAndServe (options .ListenAddress , Log (http .FileServer (http .Dir (options .Folder )))))
3334}
3435
36+ // Log middleware
3537func Log (handler http.Handler ) http.Handler {
3638 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
3739 fullRequest , _ := httputil .DumpRequest (r , true )
@@ -40,7 +42,7 @@ func Log(handler http.Handler) http.Handler {
4042
4143 if options .Verbose {
4244 headers := new (bytes.Buffer )
43- lrw .Header ().Write (headers )
45+ lrw .Header ().Write (headers ) //nolint
4446 log .Printf ("\n Remote Address: %s\n %s\n %s %d %s\n %s\n %s\n " , r .RemoteAddr , string (fullRequest ), r .Proto , lrw .statusCode , http .StatusText (lrw .statusCode ), headers .String (), string (lrw .Data ))
4547 } else {
4648 log .Printf ("%s \" %s %s %s\" %d %d" , r .RemoteAddr , r .Method , r .URL , r .Proto , lrw .statusCode , len (lrw .Data ))
@@ -54,9 +56,8 @@ type loggingResponseWriter struct {
5456 Data []byte
5557}
5658
59+ // NewLoggingResponseWriter structure
5760func NewLoggingResponseWriter (w http.ResponseWriter ) * loggingResponseWriter {
58- // WriteHeader(int) is not called if our response implicitly returns 200 OK, so
59- // we default to that status code.
6061 return & loggingResponseWriter {w , http .StatusOK , []byte {}}
6162}
6263
0 commit comments