示例#1
0
文件: main.go 项目: andviro/noodle
func apiDetail(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	id := wok.Var(ctx, "id")
	res := struct {
		ID string
	}{id}
	return render.Yield(ctx, 201, res)
}
示例#2
0
func genericRenderTest(mw noodle.Middleware, data interface{}, mutators ...headerMutator) (w *httptest.ResponseRecorder, err error) {
	h := noodle.New(mw).Then(
		func(c context.Context, w http.ResponseWriter, r *http.Request) error {
			return render.Yield(c, 200, data)
		})

	r, _ := http.NewRequest("GET", "http://localhost/testId", nil)
	for _, m := range mutators {
		m(r)
	}
	w = httptest.NewRecorder()
	err = h(context.TODO(), w, r)
	return
}
示例#3
0
文件: main.go 项目: andviro/noodle
func dashIndex(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	res := map[string]interface{}{
		"User": mw.GetUser(ctx),
	}
	return render.Yield(ctx, 201, res)
}
示例#4
0
文件: main.go 项目: andviro/noodle
func apiIndex(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	res := []int{1, 2, 3, 4, 5}
	return render.Yield(ctx, 200, res)
}