dns-api: add debug endpoint
Change-Id: I7e2a6546884b43ad9b377d19b480efd52e905c32
diff --git a/core/dns-api/server.go b/core/dns-api/server.go
index d67ccf6..1156d8d 100644
--- a/core/dns-api/server.go
+++ b/core/dns-api/server.go
@@ -2,6 +2,7 @@
import (
"encoding/json"
+ "io"
"fmt"
"net/http"
"strings"
@@ -34,6 +35,7 @@
m.HandleFunc("/create-a-record", s.createARecord)
m.HandleFunc("/delete-a-record", s.deleteARecord)
m.HandleFunc("/delete-txt-record", s.deleteTxtRecord)
+ m.HandleFunc("/", s.getAll)
return s
}
@@ -41,10 +43,13 @@
return s.s.ListenAndServe()
}
-type record struct {
- Domain string `json:"domain,omitempty"`
- Entry string `json:"entry,omitempty"`
- Text string `json:"text,omitempty"`
+func (s *Server) getAll(w http.ResponseWriter, r *http.Request) {
+ all, err := s.store.All()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ return
+ }
+ io.WriteString(w, all)
}
func (s *Server) recordsToPublish(w http.ResponseWriter, r *http.Request) {
@@ -65,6 +70,12 @@
}
}
+type record struct {
+ Domain string `json:"domain,omitempty"`
+ Entry string `json:"entry,omitempty"`
+ Text string `json:"text,omitempty"`
+}
+
func (s *Server) createTxtRecord(w http.ResponseWriter, r *http.Request) {
var req record
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {