firestormy/server/delete.go

35 lines
880 B
Go
Executable File

package server
import (
"gogs.inhome.blapointe.com/local/firestormy/config"
"gogs.inhome.blapointe.com/local/firestormy/config/ns"
"gogs.inhome.blapointe.com/local/firestormy/scheduler"
"gogs.inhome.blapointe.com/local/logb"
"net/http"
"strings"
)
func (s *Server) delete(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] delete %s", r.URL.Path)
keys := strings.Split(r.URL.Path, "/")
key := keys[len(keys)-1]
j := &scheduler.Job{}
b, err := config.Store.Get(key, ns.Jobs...)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
if err := j.Decode(b); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := scheduler.Schedule.Remove(j); err != nil {
if err := j.Decode(b); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
w.Write([]byte("{}"))
}