...

/

Adding Finishing Touches to the REST API Server

Adding Finishing Touches to the REST API Server

Learn how to run the application with the to-do API.

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 m.Handle() to handle requests to the /todo route. The complete, new version of newMux() looks like this:

Access this course and 1400+ top-rated courses and projects.