Skip to content

Commit

Permalink
add debug logging for request for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
zekker6 committed Feb 25, 2023
1 parent ebeecc0 commit 1d70060
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -110,7 +113,6 @@ func GetMux(p provider.Provider) *http.ServeMux {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
})

return m
Expand Down

0 comments on commit 1d70060

Please sign in to comment.