From 1d70060ff94013ac5ff120aff8f65a29cf521110 Mon Sep 17 00:00:00 2001 From: Zakhar Bessarab Date: Sat, 25 Feb 2023 12:04:06 +0400 Subject: [PATCH] add debug logging for request for easier debugging --- server/mux.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server/mux.go b/server/mux.go index 8aee84c..6c37b88 100644 --- a/server/mux.go +++ b/server/mux.go @@ -25,12 +25,15 @@ func GetMux(p provider.Provider) *http.ServeMux { m := http.NewServeMux() m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + log.WithField("path", r.URL.Path).WithField("method", r.Method).Debug("Received request") w.Header().Set("Vary", "Content-Type") w.Header().Set("Content-Type", "application/external.dns.plugin+json;version=1") w.WriteHeader(http.StatusOK) }) m.HandleFunc("/records", func(w http.ResponseWriter, r *http.Request) { + log.WithField("path", r.URL.Path).WithField("method", r.Method).Debug("Received request") + switch r.Method { case http.MethodGet: records, err := p.Records(context.Background()) @@ -45,7 +48,6 @@ func GetMux(p provider.Provider) *http.ServeMux { w.WriteHeader(http.StatusInternalServerError) return } - w.WriteHeader(http.StatusOK) case http.MethodPost: var changes plan.Changes if err := json.NewDecoder(r.Body).Decode(&changes); err != nil { @@ -59,13 +61,14 @@ func GetMux(p provider.Provider) *http.ServeMux { w.WriteHeader(http.StatusInternalServerError) return } - w.WriteHeader(200) default: w.WriteHeader(http.StatusMethodNotAllowed) } }) m.HandleFunc("/adjustendpoints", func(w http.ResponseWriter, r *http.Request) { + log.WithField("path", r.URL.Path).WithField("method", r.Method).Debug("Received request") + if r.Method != http.MethodGet { w.WriteHeader(http.StatusMethodNotAllowed) return @@ -83,11 +86,11 @@ func GetMux(p provider.Provider) *http.ServeMux { w.WriteHeader(http.StatusInternalServerError) return } - - w.WriteHeader(http.StatusOK) }) m.HandleFunc("/propertyvaluesequals", func(w http.ResponseWriter, r *http.Request) { + log.WithField("path", r.URL.Path).WithField("method", r.Method).Debug("Received request") + if r.Method != http.MethodGet { w.WriteHeader(http.StatusMethodNotAllowed) return @@ -110,7 +113,6 @@ func GetMux(p provider.Provider) *http.ServeMux { w.WriteHeader(http.StatusInternalServerError) return } - w.WriteHeader(http.StatusOK) }) return m