O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

For the testing of the Handler or HandlerFunc, the net/http/httptest could be leveraged. This package provides the struct ResponseRecorder that is able to record the content of the response and provide it back for asserting the values. For assembling the request, the NewRequest function of the net/http package is used. 

The net/http/httptest package also contains the version of the HTTP server which starts listening on the systems chosen port on the localhost. This implementation is intended to be used for end-to-end testing.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required