Skip to content

Commit ceb4bb4

Browse files
committed
added log middleware
1 parent 2ca324f commit ceb4bb4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

internals/proxy/middlewares/log.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package middlewares
2+
3+
import (
4+
"net/http"
5+
6+
log "github.com/codeshelldev/secured-signal-api/utils/logger"
7+
)
8+
9+
type LogMiddleware struct {
10+
Next http.Handler
11+
}
12+
13+
func (data LogMiddleware) Use() http.Handler {
14+
next := data.Next
15+
16+
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
17+
log.Info("Request:", req.Method, req.URL.Path)
18+
19+
next.ServeHTTP(w, req)
20+
})
21+
}

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ func main() {
8383
Token: ENV.API_TOKEN,
8484
}
8585

86+
log_m0 := LogMiddleware{
87+
Next: auth_m1.Use(),
88+
}
89+
8690
log.Info("Initialized Proxy Handler")
8791

8892
addr := "0.0.0.0:" + ENV.PORT
8993

9094
log.Info("Server Listening on ", addr)
9195

92-
http.ListenAndServe(addr, auth_m1.Use())
96+
http.ListenAndServe(addr, log_m0.Use())
9397
}

0 commit comments

Comments
 (0)