コード例 #1
0
ファイル: test_context.go プロジェクト: smw/goweb
func MakeTestContextWithDetails(path, method string) *webcontext.WebContext {

	TestCodecService = new(codecservices.WebCodecService)
	TestResponseWriter = new(http_test.TestResponseWriter)
	TestRequest, _ = http.NewRequest(method, fmt.Sprintf("http://stretchr.org/%s", path), nil)

	return webcontext.NewWebContext(TestResponseWriter, TestRequest, TestCodecService)
}
コード例 #2
0
ファイル: http_handler.go プロジェクト: smw/goweb
// ServeHTTP servers the actual HTTP request by buidling a context and running
// it through all the handlers.
func (handler *HttpHandler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {

	// make the context
	ctx := webcontext.NewWebContext(responseWriter, request, handler.codecService)

	// run it through the handlers
	_, err := handler.Handlers.Handle(ctx)

	// do we need to handle an error?
	if err != nil {

		// set the error
		ctx.Data().Set(DataKeyForError, err)

		// tell the handler to handle it
		handler.ErrorHandler().Handle(ctx)

	}

}