Server
package revel
var (
MainRouter *Router
MainTemplateLoader *TemplateLoader
MainWatcher *Watcher
Server *http.Server
)
func Run(port int) {
address := HttpAddr
if port == 0 {
port = HttpPort
}
if port != 0 {
address = fmt.Sprintf("%s:%d", address, port)
}
MainTemplateLoader = NewTemplateLoader(TemplatePaths)
if Config.BoolDefault("watch", true) {
MainWatcher = NewWatcher()
Filters = append([]Filter{WatchFilter}, Filters...)
}
if MainWatcher != nil && Config.BoolDefault("watch.templates", true) {
MainWatcher.Listen(MainTemplateLoader, MainTemplateLoader.paths...)
} else {
MainTemplateLoader.Refresh()
}
Server = &http.Server{
Addr: address,
Handler: http.HandlerFunc(handle),
}
runStartupHooks()
go func() {
time.Sleep(100 * time.Millisecond)
fmt.Printf("Listening on port %d...\n", port)
}()
if HttpSsl {
ERROR.Fatalln("Failed to listen:",
Server.ListenAndServeTLS(HttpSslCert, HttpSslKey))
} else {
ERROR.Fatalln("Failed to listen:", Server.ListenAndServe())
}
}
func OnAppStart(f func()) {
startupHooks = append(startupHooks, f)
}