App returns the configured app named name. If that app has not yet been loaded and provisioned, it will be immediately loaded and provisioned. If no app with that name is configured, a new empty one will be instantiated instead. (The app module must still be registered.) This must not be called duri
(name string)
| 503 | // or stop App modules. The caller is expected to assert to the |
| 504 | // concrete type. |
| 505 | func (ctx Context) App(name string) (any, error) { |
| 506 | // if the app failed to load before, return the cached error |
| 507 | if err, ok := ctx.cfg.failedApps[name]; ok { |
| 508 | return nil, fmt.Errorf("loading %s app module: %v", name, err) |
| 509 | } |
| 510 | if app, ok := ctx.cfg.apps[name]; ok { |
| 511 | return app, nil |
| 512 | } |
| 513 | appRaw := ctx.cfg.AppsRaw[name] |
| 514 | modVal, err := ctx.LoadModuleByID(name, appRaw) |
| 515 | if err != nil { |
| 516 | return nil, fmt.Errorf("loading %s app module: %v", name, err) |
| 517 | } |
| 518 | if appRaw != nil { |
| 519 | ctx.cfg.AppsRaw[name] = nil // allow GC to deallocate |
| 520 | } |
| 521 | return modVal, nil |
| 522 | } |
| 523 | |
| 524 | // AppIfConfigured is like App, but it returns an error if the |
| 525 | // app has not been configured. This is useful when the app is |
no test coverage detected