InitServer initializes the server and returns the handler It can be used as an alternative entry-point if one needs the http handler to be exposed. E.g. to run on multiple addresses and ports or to set custom TLS options.
()
| 35 | // to be exposed. E.g. to run on multiple addresses and ports or to set custom |
| 36 | // TLS options. |
| 37 | func InitServer() { |
| 38 | CurrentEngine.Init(ServerEngineInit) |
| 39 | initControllerStack() |
| 40 | startupHooks.Run() |
| 41 | |
| 42 | // Load templates |
| 43 | MainTemplateLoader = NewTemplateLoader(TemplatePaths) |
| 44 | if err := MainTemplateLoader.Refresh(); err != nil { |
| 45 | serverLogger.Debug("InitServer: Main template loader failed to refresh", "error", err) |
| 46 | } |
| 47 | |
| 48 | // The "watch" config variable can turn on and off all watching. |
| 49 | // (As a convenient way to control it all together.) |
| 50 | if Config.BoolDefault("watch", true) { |
| 51 | MainWatcher = NewWatcher() |
| 52 | Filters = append([]Filter{WatchFilter}, Filters...) |
| 53 | } |
| 54 | |
| 55 | // If desired (or by default), create a watcher for templates and routes. |
| 56 | // The watcher calls Refresh() on things on the first request. |
| 57 | if MainWatcher != nil && Config.BoolDefault("watch.templates", true) { |
| 58 | MainWatcher.Listen(MainTemplateLoader, MainTemplateLoader.paths...) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Run the server. |
| 63 | // This is called from the generated main file. |