Beispiel #1
0
// GetPerson accepts a request to retrieve information about a particular person.
//
//     GET /api/people/:person
//
func GetPerson(c web.C, w http.ResponseWriter, r *http.Request) {
	var (
		ctx   = context.FromC(c)
		idStr = c.URLParams["person"]
	)

	id, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	person, err := datastore.GetPerson(ctx, id)
	if err != nil {
		log.FromContext(ctx).WithField("err", err).Error("Error getting person")
		w.WriteHeader(http.StatusNotFound)
		return
	}

	json.NewEncoder(w).Encode(person)
}
Beispiel #2
0
// GetPerson accepts a request to retrieve information about a particular person.
//
//     GET /people/:person
//
func GetPerson(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	var (
		idStr = pat.Param(ctx, "person")
	)

	id, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	person, err := datastore.GetPerson(ctx, id)
	if err != nil {
		log.Printf("error: error getting person err=%q", err)
		w.WriteHeader(http.StatusNotFound)
		return
	}

	renderTemplate(ctx, w, "person_show.tmpl", M{
		"Person": person,
	})
}