Initialize loads the app configuration and initializes templates, keys, session, route handlers, and the database connection.
(apper Apper, debug bool)
| 400 | // Initialize loads the app configuration and initializes templates, keys, |
| 401 | // session, route handlers, and the database connection. |
| 402 | func Initialize(apper Apper, debug bool) (*App, error) { |
| 403 | debugging = debug |
| 404 | |
| 405 | apper.LoadConfig() |
| 406 | |
| 407 | // Load templates |
| 408 | err := InitTemplates(apper.App().Config()) |
| 409 | if err != nil { |
| 410 | return nil, fmt.Errorf("load templates: %s", err) |
| 411 | } |
| 412 | |
| 413 | // Load keys and set up session |
| 414 | initKeyPaths(apper.App()) // TODO: find a better way to do this, since it's unneeded in all Apper implementations |
| 415 | err = InitKeys(apper) |
| 416 | if err != nil { |
| 417 | return nil, fmt.Errorf("init keys: %s", err) |
| 418 | } |
| 419 | apper.App().InitUpdates() |
| 420 | |
| 421 | apper.App().InitSession() |
| 422 | |
| 423 | apper.App().InitDecoder() |
| 424 | |
| 425 | err = ConnectToDatabase(apper.App()) |
| 426 | if err != nil { |
| 427 | return nil, fmt.Errorf("connect to DB: %s", err) |
| 428 | } |
| 429 | |
| 430 | initActivityPub(apper.App()) |
| 431 | |
| 432 | if apper.App().cfg.Email.Enabled() { |
| 433 | log.Info("Starting publish jobs queue...") |
| 434 | go startPublishJobsQueue(apper.App()) |
| 435 | } else { |
| 436 | log.Info("[jobs] Not starting publish jobs queue: no email provider is configured.") |
| 437 | } |
| 438 | |
| 439 | // Handle local timeline, if enabled |
| 440 | if apper.App().cfg.App.LocalTimeline { |
| 441 | log.Info("Initializing local timeline...") |
| 442 | initLocalTimeline(apper.App()) |
| 443 | } |
| 444 | |
| 445 | return apper.App(), nil |
| 446 | } |
| 447 | |
| 448 | func Serve(app *App, r *mux.Router) { |
| 449 | log.Info("Going to serve...") |
no test coverage detected