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:
1 parent
66473e6021
commit
9ab2da8deb
2 files changed
+13
No files matched your search
@@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user