Beispiel #1
0
	r.Path("/load").Handler(load)
	r.Path("/clean").Handler(clean)
}

var load = apiutil.Error(apiutil.Json(apiutil.Admin(
	func(w http.ResponseWriter, r *http.Request) error {
		c := appengine.NewContext(r)
		client := urlfetch.Client(c)

		cs, err := fetchCategories(client)
		if err != nil {
			return err
		}

		ms, err := fetchMedia(client)
		if err != nil {
			return err
		}

		ps, err := fetchPaintings(client)
		if err != nil {
			return err
		}

		ps.convert(w, c, cs, ms)

		return nil
	})))

var clean = apiutil.Error(apiutil.Json(apiutil.Admin(
	func(w http.ResponseWriter, r *http.Request) error {
		c := appengine.NewContext(r)
Beispiel #2
0
	p := r.Path("/paintings/{ID:[0-9]+}").Subrouter()
	p.Methods("GET").Handler(showPainting)
	p.Methods("PUT").Handler(editPainting)

	r.Methods("POST").Path("/paintings/{ID:[0-9]+}/rotate").Handler(rotatePainting)
}

var listCategories = apiutil.Error(apiutil.Json(
	func(w http.ResponseWriter, r *http.Request) error {
		c := appengine.NewContext(r)
		categories, err := GetAllCategories(c)
		if err != nil {
			return err
		}

		err = json.NewEncoder(w).Encode(categories)
		if err != nil {
			return err
		}

		return nil
	}))

var listMedia = apiutil.Error(apiutil.Json(
	func(w http.ResponseWriter, r *http.Request) error {
		c := appengine.NewContext(r)
		media, err := GetAllMedia(c)
		if err != nil {
			return err
		}