Beispiel #1
0
func deleteAllFunc(ws worker.WatchService) http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		err := ws.Clear()
		if err != nil {
			http.Error(w, err.Error(), GOOSE_ERROR)
			return
		}

		w.WriteHeader(http.StatusNoContent)
	}
}
Beispiel #2
0
func deleteOneFunc(ws worker.WatchService) http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		params := req.URL.Query()

		id, err := strconv.Atoi(params.Get(":id"))
		if err != nil {
			http.Error(w, err.Error(), GOOSE_ERROR)
			return
		}

		_, err = ws.Remove(id)
		if err != nil {
			http.Error(w, err.Error(), GOOSE_ERROR)
			return
		}

		w.WriteHeader(http.StatusNoContent)
	}
}
Beispiel #3
0
func createFunc(ws worker.WatchService) http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		watch, err := ParseJsonWatch(req)
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}

		id, tag, err := ws.Add(watch)
		if err != nil {
			http.Error(w, err.Error(), GOOSE_ERROR)
			return
		}

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusCreated)
		fmt.Fprintf(w, `{"id": %d, "tag": "%s"}`, id, tag)
	}
}