How it works…

Once we run the program, the HTTP server will start locally listening on port 8080

Next, executing a PUT request from the command line to update an employee record with the ID as 1 will give you the number of records updated in the database as a response:

$ curl -X PUT http://localhost:8080/employee/update/1?name=bar
Number of rows updated in database are :: 1

Let’s look at the program we have written:

  1. We defined an updateRecord handler, which gets the ID to be updated in the database as a URL path variable path, and the new name as the request variable, prepares an update statement with a name and UID as a placeholder, which will be replaced dynamically, executes the statement, gets the number of rows updated as a result of its execution, and writes it to an HTTP response stream.
  2. Next, we registered an updateRecord handler to be called for the URL pattern /employee/update/{id} for every PUT request with the gorilla/mux router and closed the database using the defer db.Close() statement once we return from the main() function.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.4.181