f-21: code: separate and create route fonction
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
ac43979b38
commit
327a359007
6 changed files with 145 additions and 35 deletions
|
|
@ -22,5 +22,12 @@ func (s *Server) Start(address string) {
|
|||
mux.HandleFunc("/subnets", s.SubnetsHandler)
|
||||
mux.HandleFunc("/subnets/", s.SubnetByNameHandler)
|
||||
log.Printf("API server listening on %s", address)
|
||||
log.Fatal(http.ListenAndServe(address, mux))
|
||||
log.Fatal(http.ListenAndServe(address, logMiddleware(mux)))
|
||||
}
|
||||
|
||||
func logMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL.Path)
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue