github.com/wiselike/revel-cmd@v1.2.1/model/event.go (about) 1 package model 2 3 type ( 4 // The event type. 5 Event int 6 // The event response. 7 EventResponse int 8 // The handler signature. 9 EventHandler func(typeOf Event, value interface{}) (responseOf EventResponse) 10 RevelCallback interface { 11 FireEvent(key Event, value interface{}) (response EventResponse) 12 PackageResolver(pkgName string) error 13 } 14 ) 15 16 const ( 17 // Event type when templates are going to be refreshed (receivers are registered template engines added to the template.engine conf option). 18 TEMPLATE_REFRESH_REQUESTED Event = iota 19 // Event type when templates are refreshed (receivers are registered template engines added to the template.engine conf option). 20 TEMPLATE_REFRESH_COMPLETED 21 // Event type before all module loads, events thrown to handlers added to AddInitEventHandler. 22 23 // Event type before all module loads, events thrown to handlers added to AddInitEventHandler. 24 REVEL_BEFORE_MODULES_LOADED 25 // Event type before module loads, events thrown to handlers added to AddInitEventHandler. 26 REVEL_BEFORE_MODULE_LOADED 27 // Event type after module loads, events thrown to handlers added to AddInitEventHandler. 28 REVEL_AFTER_MODULE_LOADED 29 // Event type after all module loads, events thrown to handlers added to AddInitEventHandler. 30 REVEL_AFTER_MODULES_LOADED 31 32 // Event type before server engine is initialized, receivers are active server engine and handlers added to AddInitEventHandler. 33 ENGINE_BEFORE_INITIALIZED 34 // Event type before server engine is started, receivers are active server engine and handlers added to AddInitEventHandler. 35 ENGINE_STARTED 36 // Event type after server engine is stopped, receivers are active server engine and handlers added to AddInitEventHandler. 37 ENGINE_SHUTDOWN 38 39 // Called before routes are refreshed. 40 ROUTE_REFRESH_REQUESTED 41 // Called after routes have been refreshed. 42 ROUTE_REFRESH_COMPLETED 43 44 // Fired when a panic is caught during the startup process. 45 REVEL_FAILURE 46 ) 47 48 var initEventList = []EventHandler{} // Event handler list for receiving events 49 50 // Fires system events from revel. 51 func RaiseEvent(key Event, value interface{}) (response EventResponse) { 52 for _, handler := range initEventList { 53 response |= handler(key, value) 54 } 55 return 56 } 57 58 // Add event handler to listen for all system events. 59 func AddInitEventHandler(handler EventHandler) { 60 initEventList = append(initEventList, handler) 61 }