package http import ( "log" "net/http" "sync" ) // Main router // Twilio handler var server = &struct { router *http.ServeMux lock sync.Mutex }{ router: http.NewServeMux(), } // AddRoute is used to set up routes. // // NB: no checking is done yet for duplicate patterns. func AddRoute(pattern string, handler func(http.ResponseWriter, *http.Request)) { server.lock.Lock() defer server.lock.Unlock() server.router.HandleFunc(pattern, handler) } func Start(addr string) { go log.Print(http.ListenAndServe(addr, server.router)) }