From 8f187d41d48593c5b342641d61c084aaa8b9d075 Mon Sep 17 00:00:00 2001 From: sia Date: Mon, 25 Nov 2024 10:48:17 +0800 Subject: [PATCH] add log --- handler/url.go | 4 +++- main.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/handler/url.go b/handler/url.go index 244f0bc..9701368 100644 --- a/handler/url.go +++ b/handler/url.go @@ -9,6 +9,7 @@ import ( "github.com/gorilla/mux" "github.com/sianao/gitproxy/moudule" "github.com/sianao/gitproxy/router" + "github.com/sirupsen/logrus" ) const ( @@ -51,7 +52,7 @@ func urlProcess(w http.ResponseWriter, r *http.Request) string { return "" } } -func NewHandler(route *mux.Router) http.HandlerFunc { +func NewHandler(route *mux.Router, log *logrus.Logger) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.RequestURI == "/" || strings.HasPrefix(r.RequestURI, "/_next/") { router.ServeHTTP(w, r, route) @@ -59,6 +60,7 @@ func NewHandler(route *mux.Router) http.HandlerFunc { } var types = urlProcess(w, r) if types == "" { + log.Errorln(r.RequestURI) return } //去除掉host方便进入路由匹配 diff --git a/main.go b/main.go index 3142912..caae613 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ func main() { l := logrus.New() router := router.NewRouter(l) srv := &http.Server{ - Handler: handler.NewHandler(router), + Handler: handler.NewHandler(router, l), Addr: "0.0.0.0:8888", WriteTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second,