Mount attaches another app instance as a sub-router along a routing path. It's very useful to split up a large API as many independent routers and compose them as a single service using Mount. The fiber's error handler and any of the fiber's sub apps are added to the application's error handlers to
(prefix string, subApp *App)
| 42 | // any of the fiber's sub apps are added to the application's error handlers |
| 43 | // to be invoked on errors that happen within the prefix route. |
| 44 | func (app *App) mount(prefix string, subApp *App) Router { |
| 45 | prefix = utils.TrimRight(prefix, '/') |
| 46 | if prefix == "" { |
| 47 | prefix = "/" |
| 48 | } |
| 49 | |
| 50 | app.mutex.Lock() |
| 51 | // Support for configs of mounted-apps and sub-mounted-apps |
| 52 | for mountedPrefixes, subApp := range subApp.mountFields.appList { |
| 53 | path := getGroupPath(prefix, mountedPrefixes) |
| 54 | |
| 55 | subApp.mountFields.mountPath = path |
| 56 | app.mountFields.appList[path] = subApp |
| 57 | } |
| 58 | app.mutex.Unlock() |
| 59 | |
| 60 | // register mounted group |
| 61 | mountGroup := &Group{Prefix: prefix, app: subApp} |
| 62 | app.register([]string{methodUse}, prefix, mountGroup) |
| 63 | |
| 64 | // Execute onMount hooks |
| 65 | if err := subApp.hooks.executeOnMountHooks(app); err != nil { |
| 66 | panic(err) |
| 67 | } |
| 68 | |
| 69 | return app |
| 70 | } |
| 71 | |
| 72 | // Mount attaches another app instance as a sub-router along a routing path. |
| 73 | // It's very useful to split up a large API as many independent routers and |
no test coverage detected