Delete records

This commit is contained in:
Magnus Åhall 2026-02-25 21:05:02 +01:00
parent 52bd8b34b3
commit df936baa8f
5 changed files with 167 additions and 23 deletions

View file

@ -7,6 +7,7 @@ import (
// Standard
"embed"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@ -33,6 +34,7 @@ func registerWebserverHandlers() {
http.HandleFunc("/", rootHandler)
http.HandleFunc("/record/save", actionRecordSave)
http.HandleFunc("/record/delete/{id}", actionRecordDelete)
}
func startWebserver() {
@ -110,6 +112,30 @@ func actionRecordSave(w http.ResponseWriter, r *http.Request) {
record = NewDNSRecord(entry)
j, _ := json.Marshal(struct{ OK bool; Record DNSRecord }{true, record})
j, _ := json.Marshal(struct {
OK bool
Record DNSRecord
}{true, record})
w.Write(j)
}
func actionRecordDelete(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
if id == "" {
httpError(w, errors.New("No ID provided"))
return
}
err := device.DeleteDNSEntry(id)
if err != nil {
httpError(w, err)
logger.Error("webserver", "op", "record_delete", "error", err)
return
}
j, _ := json.Marshal(struct {
OK bool
}{true})
w.Write(j)
}