Introduce single-address Free() and rename the previous one to Delete()

This commit is contained in:
Bryan Boreham committed 2015-06-10 17:21:16 +01:00
1 parent d20d2e9142
commit a617e7918c
4 files changed
+52 -22

No files matched your search

+16 -1
View File
@@ -81,9 +81,24 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router) {
fmt.Fprintf(w, "%s/%d", newAddr.String(), alloc.defaultSubnet.PrefixLen)
})
router.Methods("DELETE").Path("/ip/{id}/{ip}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
ident := vars["id"]
ipStr := vars["ip"]
if ip, err := address.ParseIP(ipStr); err != nil {
badRequest(w, err)
return
} else if err := alloc.Free(ident, ip); err != nil {
badRequest(w, fmt.Errorf("Unable to free: %s", err))
return
}
w.WriteHeader(204)
})
router.Methods("DELETE").Path("/ip/{id}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ident := mux.Vars(r)["id"]
if err := alloc.Free(ident); err != nil {
if err := alloc.Delete(ident); err != nil {
badRequest(w, err)
return
}