@@ -16,18 +16,27 @@ import (
16
16
17
17
"github.com/agtorre/gocolorize"
18
18
"github.com/revel/config"
19
+ "sort"
19
20
)
20
21
21
22
const (
22
23
// RevelImportPath Revel framework import path
23
24
RevelImportPath = "github.com/revel/revel"
24
25
)
26
+ const (
27
+ // Called when templates are going to be refreshed (receivers are registered template engines added to the template.engine conf option)
28
+ TEMPLATE_REFRESH_REQUESTED = iota
29
+ // Called when templates are refreshed (receivers are registered template engines added to the template.engine conf option)
30
+ TEMPLATE_REFRESH_COMPLETED
25
31
32
+ )
26
33
type revelLogs struct {
27
34
c gocolorize.Colorize
28
35
w io.Writer
29
36
}
30
37
38
+ type EventHandler func (typeOf int , value interface {}) (responseOf int )
39
+
31
40
func (r * revelLogs ) Write (p []byte ) (n int , err error ) {
32
41
return r .w .Write ([]byte (r .c .Paint (string (p ))))
33
42
}
@@ -111,6 +120,7 @@ var (
111
120
// Private
112
121
secretKey []byte // Key used to sign cookies. An empty key disables signing.
113
122
packaged bool // If true, this is running from a pre-built package.
123
+ initEventList = []EventHandler {} // Event handler list for receiving events
114
124
)
115
125
116
126
// Init initializes Revel -- it provides paths for getting around the app.
@@ -230,6 +240,25 @@ func Init(mode, importPath, srcPath string) {
230
240
INFO .Printf ("Initialized Revel v%s (%s) for %s" , Version , BuildDate , MinimumGoVersion )
231
241
}
232
242
243
+ // Fires system events from revel
244
+ func fireEvent (key int , value interface {}) (response int ) {
245
+ for _ , handler := range initEventList {
246
+ response |= handler (key , value )
247
+ }
248
+ return
249
+ }
250
+
251
+ // Add event handler to listen for all system events
252
+ func AddInitEventHandler (handler EventHandler ) {
253
+ initEventList = append (initEventList , handler )
254
+ return
255
+ }
256
+
257
+ func SetSecretKey (newKey []byte ) error {
258
+ secretKey = newKey
259
+ return nil
260
+ }
261
+
233
262
// Create a logger using log.* directives in app.conf plus the current settings
234
263
// on the default logger.
235
264
func getLogger (name string ) * log.Logger {
@@ -325,7 +354,17 @@ type Module struct {
325
354
}
326
355
327
356
func loadModules () {
357
+ keys := []string {}
328
358
for _ , key := range Config .Options ("module." ) {
359
+ keys = append (keys , key )
360
+ }
361
+ // Reorder module order by key name, a poor mans sort but at least it is consistent
362
+ sort .Strings (keys )
363
+ for _ , key := range keys {
364
+ println ("Sorted keys" , key )
365
+
366
+ }
367
+ for _ , key := range keys {
329
368
moduleImportPath := Config .StringDefault (key , "" )
330
369
if moduleImportPath == "" {
331
370
continue
@@ -335,7 +374,13 @@ func loadModules() {
335
374
if err != nil {
336
375
log .Fatalln ("Failed to load module. Import of" , moduleImportPath , "failed:" , err )
337
376
}
338
- addModule (key [len ("module." ):], moduleImportPath , modulePath )
377
+ // Drop anything between module.???.<name of module>
378
+ subKey := key [len ("module." ):]
379
+ if index := strings .Index (subKey , "." ); index > - 1 {
380
+ subKey = subKey [index + 1 :]
381
+ }
382
+
383
+ addModule (subKey , moduleImportPath , modulePath )
339
384
}
340
385
}
341
386
0 commit comments