MCPcopy
hub / github.com/gofiber/fiber / mount

Method mount

mount.go:75–102  ·  view source on GitHub ↗

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.

(prefix string, subApp *App)

Source from the content-addressed store, hash-verified

73// It's very useful to split up a large API as many independent routers and
74// compose them as a single service using Mount.
75func (grp *Group) mount(prefix string, subApp *App) Router {
76 groupPath := getGroupPath(grp.Prefix, prefix)
77 groupPath = utils.TrimRight(groupPath, '/')
78 if groupPath == "" {
79 groupPath = "/"
80 }
81
82 grp.app.mutex.Lock()
83 // Support for configs of mounted-apps and sub-mounted-apps
84 for mountedPrefixes, subApp := range subApp.mountFields.appList {
85 path := getGroupPath(groupPath, mountedPrefixes)
86
87 subApp.mountFields.mountPath = path
88 grp.app.mountFields.appList[path] = subApp
89 }
90 grp.app.mutex.Unlock()
91
92 // register mounted group
93 mountGroup := &Group{Prefix: groupPath, app: subApp}
94 grp.app.register([]string{methodUse}, groupPath, mountGroup)
95
96 // Execute onMount hooks
97 if err := subApp.hooks.executeOnMountHooks(grp.app); err != nil {
98 panic(err)
99 }
100
101 return grp
102}
103
104// MountPath returns the route pattern where the current app instance was mounted as a sub-application.
105func (app *App) MountPath() string {

Callers 1

UseMethod · 0.95

Calls 5

getGroupPathFunction · 0.85
registerMethod · 0.80
executeOnMountHooksMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected