O'Reilly logo

Distributed Computing with Go by V.N. Nikhil Anurag

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

books-handler/actions.go

This source file consists of functions to handle each of the HTTP request's method calls:

// restServer/books-handler/actions.go package booksHandler import ( "net/http" ) // actOn{GET, POST, DELETE, PUT} functions return Response based on specific Request type. func actOnGET(books map[string]bookResource, act Action) { // These initialized values cover the case: // Request asked for an id that doesn't exist. status := http.StatusNotFound bookResult := []bookResource{} if act.Id == "" { // Request asked for all books. status = http.StatusOK for _, book := range books { bookResult = append(bookResult, book) } } else if book, exists := books[act.Id]; exists { // Request asked for a specific book and the id exists. status ...

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