コード例 #1
0
func setupNamedSizesServer() func(string, string) *httptest.ResponseRecorder {
	router := mux.NewRouter()
	imgSrv := th.SetupImgServer()
	srv := btcdn.NewNamedSizesServer(imgSrv, router)

	return func(method, path string) *httptest.ResponseRecorder {
		rec := httptest.NewRecorder()
		req, err := http.NewRequest(method, "http://example.com"+path, nil)

		if err != nil {
			log.Fatal(err)
		}

		srv.ServeHTTP(rec, req)

		return rec
	}
}
コード例 #2
0
ファイル: cached_endpoint_test.go プロジェクト: bootic/btcdn
func setupCachedEndpoint() func(string, string) *httptest.ResponseRecorder {
	router := mux.NewRouter()
	imgSrv := th.SetupImgServer()
	cached := btcdn.NewCachedEndpoint(imgSrv, "../fixtures/test")
	named := btcdn.NewNamedSizesServer(cached, router)

	return func(method, path string) *httptest.ResponseRecorder {
		rec := httptest.NewRecorder()
		req, err := http.NewRequest(method, "http://example.com"+path, nil)

		if err != nil {
			log.Fatal(err)
		}

		named.ServeHTTP(rec, req)

		return rec
	}
}