コード例 #1
0
// ListPeople accepts a request to retrieve a list of people.
//
//     GET /api/people
//
func ListPeople(c web.C, w http.ResponseWriter, r *http.Request) {
	var (
		ctx    = context.FromC(c)
		limit  = handler.ToLimit(r)
		offset = handler.ToOffset(r)
	)

	people, err := datastore.ListPeople(ctx, limit, offset)
	if err != nil {
		log.FromContext(ctx).WithField("err", err).Error("Error listing people")
		w.WriteHeader(http.StatusNotFound)
		return
	}

	json.NewEncoder(w).Encode(people)
}
コード例 #2
0
ファイル: person.go プロジェクト: andrew-d/go-webapp-skeleton
// ListPeople shows a list of all people
//
//     GET /people
//
func ListPeople(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	var (
		limit  = handler.ToLimit(r)
		offset = handler.ToOffset(r)
	)

	people, err := datastore.ListPeople(ctx, limit, offset)
	if err != nil {
		log.Printf("error: error listing people err=%q", err)
		w.WriteHeader(http.StatusNotFound)
		return
	}

	renderTemplate(ctx, w, "person_list.tmpl", M{
		"People": people,
	})
}
コード例 #3
0
// ListPeople shows a list of all people
//
//     GET /people
//
func ListPeople(c web.C, w http.ResponseWriter, r *http.Request) {
	var (
		ctx    = context.FromC(c)
		limit  = handler.ToLimit(r)
		offset = handler.ToOffset(r)
	)

	people, err := datastore.ListPeople(ctx, limit, offset)
	if err != nil {
		log.FromContext(ctx).WithField("err", err).Error("Error listing people")
		w.WriteHeader(http.StatusNotFound)
		return
	}

	renderTemplate(ctx, w, "person_list.tmpl", M{
		"People": people,
	})
}