@@ -40,14 +40,18 @@ func (m *handlerMappings) remove(name string, group int) bool {
40
40
return false
41
41
}
42
42
43
- for i , handler := range currHandlers {
43
+ for idx , handler := range currHandlers {
44
44
if handler .Name () != name {
45
45
continue
46
46
}
47
47
48
48
// Only one item left, so just delete the group entirely.
49
49
if len (currHandlers ) == 1 {
50
- m .handlerGroups = append (m .handlerGroups [:group ], m .handlerGroups [group + 1 :]... )
50
+ // get index of the current group to remove it from the list of handlergroups
51
+ gIdx := getIndex (group , m .handlerGroups )
52
+ if gIdx != - 1 {
53
+ m .handlerGroups = append (m .handlerGroups [:gIdx ], m .handlerGroups [gIdx + 1 :]... )
54
+ }
51
55
delete (m .handlers , group )
52
56
return true
53
57
}
@@ -57,13 +61,22 @@ func (m *handlerMappings) remove(name string, group int) bool {
57
61
newHandlers := make ([]Handler , len (m .handlers [group ]))
58
62
copy (newHandlers , m .handlers [group ])
59
63
60
- m .handlers [group ] = append (newHandlers [:i ], newHandlers [i + 1 :]... )
64
+ m .handlers [group ] = append (newHandlers [:idx ], newHandlers [idx + 1 :]... )
61
65
return true
62
66
}
63
67
// handler not found - removal failed.
64
68
return false
65
69
}
66
70
71
+ func getIndex (find int , is []int ) int {
72
+ for i , v := range is {
73
+ if v == find {
74
+ return i
75
+ }
76
+ }
77
+ return - 1
78
+ }
79
+
67
80
func (m * handlerMappings ) removeGroup (group int ) bool {
68
81
m .mutex .Lock ()
69
82
defer m .mutex .Unlock ()
@@ -73,12 +86,12 @@ func (m *handlerMappings) removeGroup(group int) bool {
73
86
return false
74
87
}
75
88
76
- for j , handlerGroup := range m .handlerGroups {
89
+ for idx , handlerGroup := range m .handlerGroups {
77
90
if handlerGroup != group {
78
91
continue
79
92
}
80
93
81
- m .handlerGroups = append (m .handlerGroups [:j ], m .handlerGroups [j + 1 :]... )
94
+ m .handlerGroups = append (m .handlerGroups [:idx ], m .handlerGroups [idx + 1 :]... )
82
95
delete (m .handlers , group )
83
96
// Group found, and deleted. Success!
84
97
return true
0 commit comments