Пример #1
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)
	}
}