February 2018
Intermediate to advanced
246 pages
6h 3m
English
The handler.go source file consists of all logic required to work with and handle book requests. Note that apart from consisting the logic for handling HTTP requests, it also deals with maintaining the state of books on the server:
// restServer/books-handler/handler.go package booksHandler import ( "encoding/json" "fmt" "io/ioutil" "log" "net/http" ) // StartBooksManager starts a goroutine that changes the state of books (map). // Primary reason to use a goroutine instead of directly manipulating the books map is to ensure // that we do not have multiple requests changing books' state simultaneously. func StartBooksManager(books map[string]bookResource, actionCh <-chan Action) { newID := len(books) for { select { ...Read now
Unlock full access