Skip to content

Commit 421039f

Browse files
committed
remove some parts
1 parent 400c828 commit 421039f

File tree

3 files changed

+0
-90
lines changed

3 files changed

+0
-90
lines changed

Diff for: app.go

-27
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ type App struct {
116116
getString func(b []byte) string
117117
// Mounted and main apps
118118
appList map[string]*App
119-
// If application is a parent, It returns nil. It can accessible only from sub app
120-
parent *App
121-
// Mounted sub app's path
122-
mountpath string
123119
// Hooks
124120
hooks *hooks
125121
// Latest route & group
@@ -469,8 +465,6 @@ func New(config ...Config) *App {
469465
getBytes: utils.UnsafeBytes,
470466
getString: utils.UnsafeString,
471467
appList: make(map[string]*App),
472-
parent: nil,
473-
mountpath: "",
474468
latestRoute: &Route{},
475469
latestGroup: &Group{},
476470
customBinders: []CustomBinder{},
@@ -709,25 +703,6 @@ func (app *App) All(path string, handlers ...Handler) Router {
709703
return app
710704
}
711705

712-
// The MountPath property contains one or more path patterns on which a sub-app was mounted.
713-
func (app *App) MountPath() string {
714-
return app.mountpath
715-
}
716-
717-
// The mount event is fired on a sub-app, when it is mounted on a parent app. The parent app is passed to the callback function.
718-
func (app *App) OnMount(callback func(parent *App)) {
719-
if app.parent == nil {
720-
panic("not mounted sub app to parent app")
721-
}
722-
723-
if app.mountpath == "" {
724-
panic("onmount cannot be used on parent app")
725-
}
726-
727-
// returns parent app in callback
728-
callback(app.parent)
729-
}
730-
731706
// Group is used for Routes with common prefix to define a new sub-router with optional middleware.
732707
//
733708
// api := app.Group("/api")
@@ -1142,8 +1117,6 @@ func (app *App) mount(prefix string, sub *App) *App {
11421117
// Support for configs of mounted-apps and sub-mounted-apps
11431118
for mountedPrefixes, subApp := range sub.appList {
11441119
app.appList[prefix+mountedPrefixes] = subApp
1145-
subApp.parent = app
1146-
subApp.mountpath = prefix + mountedPrefixes
11471120
subApp.init()
11481121
}
11491122

Diff for: app_test.go

-61
Original file line numberDiff line numberDiff line change
@@ -325,67 +325,6 @@ func Test_App_Mount(t *testing.T) {
325325
utils.AssertEqual(t, uint32(2), app.handlersCount)
326326
}
327327

328-
func Test_App_MountPath(t *testing.T) {
329-
parent := New()
330-
sub := New()
331-
sub1 := New()
332-
333-
parent.Use("/sub", sub)
334-
parent.Use("/sub1", sub1)
335-
336-
utils.AssertEqual(t, "/sub", sub.MountPath())
337-
utils.AssertEqual(t, "/sub1", sub1.MountPath())
338-
}
339-
340-
func Benchmark_App_MountPath(b *testing.B) {
341-
parent := New()
342-
sub := New()
343-
344-
parent.Use("/sub", sub)
345-
346-
var mp string
347-
b.ReportAllocs()
348-
b.ResetTimer()
349-
350-
for n := 0; n < b.N; n++ {
351-
mp = sub.MountPath()
352-
}
353-
354-
utils.AssertEqual(b, "/sub", mp)
355-
}
356-
357-
func Test_App_OnMount(t *testing.T) {
358-
app := New()
359-
sub := New()
360-
sub1 := New()
361-
362-
app.Use("/sub", sub)
363-
364-
sub.OnMount(func(parent *App) {
365-
//Check parent app
366-
utils.AssertEqual(t, app.mountpath, parent.mountpath)
367-
})
368-
369-
sub.OnMount(func(parent *App) {
370-
utils.AssertEqual(t, parent != nil, true)
371-
})
372-
373-
defer func() {
374-
if err := recover(); err != nil {
375-
utils.AssertEqual(t, "not mounted sub app to parent app", fmt.Sprintf("%s", err))
376-
}
377-
}()
378-
379-
sub1.OnMount(func(parent *App) {})
380-
381-
defer func() {
382-
if err := recover(); err != nil {
383-
utils.AssertEqual(t, "onmount cannot be used on parent app", fmt.Sprintf("%s", err))
384-
}
385-
}()
386-
app.OnMount(func(parent *App) {})
387-
}
388-
389328
func Test_App_Use_Params(t *testing.T) {
390329
app := New()
391330

Diff for: group.go

-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ func (grp *Group) mount(prefix string, sub *App) Router {
3838
// Support for configs of mounted-apps and sub-mounted-apps
3939
for mountedPrefixes, subApp := range sub.appList {
4040
grp.app.appList[groupPath+mountedPrefixes] = subApp
41-
subApp.parent = grp.app
42-
subApp.mountpath = groupPath + mountedPrefixes
4341
subApp.init()
4442
}
4543

0 commit comments

Comments
 (0)