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

main.go

The main.go source file consists of code mostly responsible for assembling and running the web server. The logic to actually respond to HTTP requests are distributed across other files:

// restServer/main.go package main import ( "fmt" "log" "net/http" booksHandler "github.com/last-ent/distributed-go/chapter4/books-handler" ) func main() { // Get state (map) for books available on REST server. books := booksHandler.GetBooks() log.Println(fmt.Sprintf("%+v", books)) actionCh := make(chan booksHandler.Action) // Start goroutine responsible for handling interaction with the books map go booksHandler.StartBooksManager(books, actionCh) http.HandleFunc("/api/books/", booksHandler.MakeHandler(booksHandler.BookHandler, "/api/books/", actionCh)) ...

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