package domain import ( "encoding/json" "log" "net/http" "strconv" "github.com/kentonh/gPanel/pkg/database" ) func Unlink(res http.ResponseWriter, req *http.Request, logger *log.Logger) bool { if req.Method != "DELETE" { logger.Println(req.URL.Path + "::" + req.Method + "::" + strconv.Itoa(http.StatusMethodNotAllowed) + "::" + http.StatusText(http.StatusMethodNotAllowed)) http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) return false } var unlinkDomainRequestData struct { Domain string `json:"domain"` } err := json.NewDecoder(req.Body).Decode(&unlinkDomainRequestData) if err != nil { logger.Println(req.URL.Path + "::" + err.Error()) http.Error(res, err.Error(), http.StatusBadRequest) return false } ds, err := database.Open("server/" + database.DB_DOMAINS) if err != nil || ds == nil { logger.Println(req.URL.Path + "::" + err.Error()) http.Error(res, err.Error(), http.StatusInternalServerError) return false } defer ds.Close() err = ds.Delete(database.BUCKET_DOMAINS, []byte(unlinkDomainRequestData.Domain)) if err != nil { logger.Println(req.URL.Path + "::" + err.Error()) http.Error(res, err.Error(), http.StatusInternalServerError) return false } res.WriteHeader(http.StatusNoContent) return true }