firestormy/server/get.go

31 lines
754 B
Go
Executable File

package server
import (
"encoding/json"
"gitea.inhome.blapointe.com/local/firestormy/config"
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
"gitea.inhome.blapointe.com/local/firestormy/scheduler"
"gitea.inhome.blapointe.com/local/logb"
"net/http"
"strings"
)
func (s *Server) get(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] get %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
}
json.NewEncoder(w).Encode(toMap(j, true))
}