Пример #1
0
// 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)

	// copy the data
	for k, v := range handler.Data {
		ctx.Data()[k] = v
	}

	// 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)

	}

}
Пример #2
0
func MakeTestContextWithFullDetails(path, method, body string) *webcontext.WebContext {
	TestCodecService = codecsservices.NewWebCodecService()
	TestResponseWriter = new(http_test.TestResponseWriter)

	if len(body) == 0 {
		TestRequest, _ = http.NewRequest(method, path, nil)
	} else {
		TestRequest, _ = http.NewRequest(method, path, strings.NewReader(body))
	}

	return webcontext.NewWebContext(TestResponseWriter, TestRequest, TestCodecService)

}