@@ -10,6 +10,8 @@ import (
10
10
"sync"
11
11
12
12
"github.com/gorilla/mux"
13
+
14
+ "github.com/ava-labs/avalanchego/utils/set"
13
15
)
14
16
15
17
var (
@@ -22,15 +24,15 @@ type router struct {
22
24
router * mux.Router
23
25
24
26
routeLock sync.Mutex
25
- reservedRoutes map [string ]bool // Reserves routes so that there can't be alias that conflict
27
+ reservedRoutes set. Set [string ] // Reserves routes so that there can't be alias that conflict
26
28
aliases map [string ][]string // Maps a route to a set of reserved routes
27
29
routes map [string ]map [string ]http.Handler // Maps routes to a handler
28
30
}
29
31
30
32
func newRouter () * router {
31
33
return & router {
32
34
router : mux .NewRouter (),
33
- reservedRoutes : make ( map [string ]bool ) ,
35
+ reservedRoutes : set. Set [string ]{} ,
34
36
aliases : make (map [string ][]string ),
35
37
routes : make (map [string ]map [string ]http.Handler ),
36
38
}
@@ -68,7 +70,7 @@ func (r *router) AddRouter(base, endpoint string, handler http.Handler) error {
68
70
}
69
71
70
72
func (r * router ) addRouter (base , endpoint string , handler http.Handler ) error {
71
- if r .reservedRoutes [ base ] {
73
+ if r .reservedRoutes . Contains ( base ) {
72
74
return fmt .Errorf ("couldn't route to %s as that route is either aliased or already maps to a handler" , base )
73
75
}
74
76
@@ -113,13 +115,13 @@ func (r *router) AddAlias(base string, aliases ...string) error {
113
115
defer r .routeLock .Unlock ()
114
116
115
117
for _ , alias := range aliases {
116
- if r .reservedRoutes [ alias ] {
118
+ if r .reservedRoutes . Contains ( alias ) {
117
119
return fmt .Errorf ("couldn't alias to %s as that route is either already aliased or already maps to a handler" , alias )
118
120
}
119
121
}
120
122
121
123
for _ , alias := range aliases {
122
- r .reservedRoutes [ alias ] = true
124
+ r .reservedRoutes . Add ( alias )
123
125
}
124
126
125
127
r .aliases [base ] = append (r .aliases [base ], aliases ... )
0 commit comments