Esempio n. 1
0
func Test1(t *testing.T) {
	assert := assert.New(t)
	stack := httpctx.Use(middleware1, middleware2)
	assert.NotNil(stack)

	http.Handle("/api/whatever", stack.Handle(doWhateverHandler))
}
Esempio n. 2
0
func Example() {
	public := httpctx.Use(ensureHttps)
	authenticate := public.Use(authenticate, ensureAdmin)

	http.Handle("/admin", authenticate.HandleFunc(admin))
	http.Handle("/", public.HandleFunc(index))
	http.ListenAndServe(":8080", nil)
}
Esempio n. 3
0
func TestHandler(t *testing.T) {
	emptyFunc := func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		return nil
	}
	for i, tc := range []struct {
		http.Handler
	}{
		{httpctx.HandleFunc(emptyFunc)},
		{httpctx.Use(middleware1).Use(middleware2).HandleFunc(emptyFunc)},
	} {
		srv := httptest.NewServer(tc.Handler)
		resp, err := http.Get(srv.URL)
		srv.Close()
		resp.Body.Close()
		if err != nil {
			t.Errorf("%d. %v", i, err)
		}
	}
}