Add GET /name handler to return all dns entries (including tombstones) for debugging.

Also, make Address marshall into json as an IP string, not a number.
This commit is contained in:
Tom Wilkie committed 2015-07-20 12:03:33 +00:00
1 parent 66473e6021
commit 9ab2da8deb
2 files changed
+13

No files matched your search

+9
View File
@@ -1,6 +1,7 @@
package nameserver
import (
"encoding/json"
"fmt"
"net/http"
@@ -82,4 +83,12 @@ func (n *Nameserver) HandleHTTP(router *mux.Router) {
router.Methods("DELETE").Path("/name/{container}/{ip}").HandlerFunc(deleteHandler)
router.Methods("DELETE").Path("/name/{container}").HandlerFunc(deleteHandler)
router.Methods("DELETE").Path("/name").HandlerFunc(deleteHandler)
router.Methods("GET").Path("/name").Headers("Accept", "application/json").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
n.RLock()
defer n.RUnlock()
if err := json.NewEncoder(w).Encode(n.entries); err != nil {
badRequest(w, fmt.Errorf("Error marshalling response: %v", err))
}
})
}
+4
View File
@@ -90,6 +90,10 @@ func (addr Address) IP4() (r net.IP) {
return
}
func (addr Address) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%q", addr.String())), nil
}
func (addr Address) String() string {
return addr.IP4().String()
}