Testing HTTP servers
The net/http/httptest
package complements the testing
package by providing HTTP server testing facilities that allow you to create test HTTP servers quickly.
For this section, suppose we extend our sorting function by converting it to an HTTP service, as given here:
package service import ( "encoding/json" "io" "net/http" "time" "github.com/PacktPublishing/Go-Recipes-for-Developers/src/chp17/ sorting/sort" ) // Common handler function for parsing the input, sorting, and // preparing the output func HandleSort(w http.ResponseWriter, req *http.Request, ascending bool) { var input []time.Time data, err := io.ReadAll(req.Body) if err != nil { http.Error...