|
| 1 | +// aah application initialization - configuration, server extensions, middleware's, etc. |
| 2 | +// Customize it per your application needs. |
| 3 | + |
| 4 | +package main |
| 5 | + |
| 6 | +import ( |
| 7 | + |
| 8 | + "aahframework.org/aah.v0" |
| 9 | + |
| 10 | + // Registering HTML minifier for web application |
| 11 | + _ "github.com/aah-cb/minify" |
| 12 | +) |
| 13 | + |
| 14 | +func init() { |
| 15 | + |
| 16 | + //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 17 | + // Server Extensions |
| 18 | + // Doc: https://docs.aahframework.org/server-extension.html |
| 19 | + // |
| 20 | + // Best Practice: Define a function with meaningful name in a package and |
| 21 | + // register it here. Extensions function name gets logged in the log, |
| 22 | + // its very helpful to have meaningful log information. |
| 23 | + // |
| 24 | + // Such as: |
| 25 | + // - Dedicated package for config loading |
| 26 | + // - Dedicated package for datasource connections |
| 27 | + // - etc |
| 28 | + //__________________________________________________________________________ |
| 29 | + |
| 30 | + // Event: OnInit |
| 31 | + // |
| 32 | + // Published right after the `aah.AppConfig()` is loaded. |
| 33 | + // |
| 34 | + // aah.OnInit(config.LoadRemote) |
| 35 | + |
| 36 | + // Event: OnStart |
| 37 | + // |
| 38 | + // Published right before the start of aah server. |
| 39 | + // |
| 40 | + // aah.OnStart(db.Connect) |
| 41 | + // aah.OnStart(cache.Load) |
| 42 | + aah.OnStart(SubscribeHTTPEvents) |
| 43 | + |
| 44 | + // Event: OnShutdown |
| 45 | + // |
| 46 | + // Published on receiving OS Signals `SIGINT` or `SIGTERM`. |
| 47 | + // |
| 48 | + // aah.OnShutdown(cache.Flush) |
| 49 | + // aah.OnShutdown(db.Disconnect) |
| 50 | + |
| 51 | + //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 52 | + // Middleware's |
| 53 | + // Doc: https://docs.aahframework.org/middleware.html |
| 54 | + // |
| 55 | + // Executed in the order they are defined. It is recommended; NOT to change |
| 56 | + // the order of pre-defined aah framework middleware's. |
| 57 | + //__________________________________________________________________________ |
| 58 | + aah.Middlewares( |
| 59 | + aah.RouteMiddleware, |
| 60 | + aah.CORSMiddleware, |
| 61 | + aah.BindMiddleware, |
| 62 | + aah.AntiCSRFMiddleware, |
| 63 | + aah.AuthcAuthzMiddleware, |
| 64 | + |
| 65 | + // |
| 66 | + // NOTE: Register your Custom middleware's right here |
| 67 | + // |
| 68 | + |
| 69 | + aah.ActionMiddleware, |
| 70 | + ) |
| 71 | + |
| 72 | + //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 73 | + // Add Application Error Handler |
| 74 | + // Doc: https://docs.aahframework.org/error-handling.html |
| 75 | + //__________________________________________________________________________ |
| 76 | + // aah.SetErrorHandler(AppErrorHandler) |
| 77 | + |
| 78 | + //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 79 | + // Add Custom Template Functions |
| 80 | + // Doc: https://docs.aahframework.org/template-funcs.html |
| 81 | + //__________________________________________________________________________ |
| 82 | + // aah.AddTemplateFunc(template.FuncMap{ |
| 83 | + // // ... |
| 84 | + // }) |
| 85 | + |
| 86 | + //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 87 | + // Add Custom Session Store |
| 88 | + // Doc: https://docs.aahframework.org/session.html |
| 89 | + //__________________________________________________________________________ |
| 90 | + // aah.AddSessionStore("redis", &RedisSessionStore{}) |
| 91 | + |
| 92 | + //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 93 | + // Add Custom value Parser |
| 94 | + // Doc: https://docs.aahframework.org/request-parameters-auto-bind.html |
| 95 | + //__________________________________________________________________________ |
| 96 | + // if err := aah.AddValueParser(reflect.TypeOf(CustomType{}), customParser); err != nil { |
| 97 | + // log.Error(err) |
| 98 | + // } |
| 99 | + |
| 100 | + //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 101 | + // Add Custom Validation Functions |
| 102 | + // Doc: https://godoc.org/gopkg.in/go-playground/validator.v9 |
| 103 | + //__________________________________________________________________________ |
| 104 | + // Obtain aah validator instance, then add yours |
| 105 | + // validator := aah.Validator() |
| 106 | + // |
| 107 | + // // Add your validation funcs |
| 108 | + |
| 109 | +} |
| 110 | + |
| 111 | +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 112 | +// HTTP Events |
| 113 | +// |
| 114 | +// Subscribing HTTP events on app start. |
| 115 | +//__________________________________________________________________________ |
| 116 | + |
| 117 | +func SubscribeHTTPEvents(_ *aah.Event) { |
| 118 | + // he := aah.AppHTTPEngine() |
| 119 | + |
| 120 | + // Event: OnRequest |
| 121 | + // he.OnRequest(myserverext.OnRequest) |
| 122 | + |
| 123 | + // Event: OnPreReply |
| 124 | + // he.OnPreReply(myserverext.OnPreReply) |
| 125 | + |
| 126 | + // Event: OnPostReply |
| 127 | + // he.OnPostReply(myserverext.OnPostReply) |
| 128 | + |
| 129 | + // Event: OnPreAuth |
| 130 | + // he.OnPreAuth(myserverext.OnPreAuth) |
| 131 | + |
| 132 | + // Event: OnPostAuth |
| 133 | + // Published right after the successful Authentication |
| 134 | + // he.OnPostAuth(myserverext.PostAuthEvent) |
| 135 | +} |
| 136 | + |
0 commit comments