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 Go: Building Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.