A multiuser Appointments Calendar

In this section, we'll quickly look at our sample Appointments Calendar application, which attempts to control consistency of specific elements to avoid obvious race conditions. The following is the full code, including the routing and templating:

package main import( "net/http" "html/template" "fmt" "github.com/gorilla/mux" "sync" "strconv" ) type User struct { Name string Times map[int] bool DateHTML template.HTML } type Page struct { Title string Body template.HTML Users map[string] User } var usersInit map[string] bool var userIndex int var validTimes []int var mutex sync.Mutex var Users map[string]User var templates = template.Must(template.New("template").ParseFiles("view_users.html", "register.html")) func ...

Get Mastering Concurrency in Go now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.