Adding Finishing Touches to the REST API Server
Explore how to enhance a Go REST API server by updating the request routing with sync.Mutex for concurrency control, creating temporary files for test data, and implementing comprehensive tests for all CRUD operations. This lesson guides you through ensuring that your API behaves correctly and handles JSON responses effectively.
Updating the newMux() function
Now we update the newMux() function to route the requests for the /todo path. We open the file server.go and update the function newMux() by defining
a new variable, mu, as a pointer to a sync.Mutex type. The pointer to Mutex implements
the interface sync.Locker, so we can use it as an input to the todoRouter() function.
Then we use the variables mu and todoFile to run the function todoRouter(), assigning
its output to a variable t. Finally, we use the variable t in the function http.StripPrefix()
to strip the /todo prefix from the URL path, passing its output to the method
...