MSP-437 reimplement routes storage

This commit is contained in:
d1slike committed 2022-08-04 21:49:13 +03:00
1 parent 5d4729e0c7
commit cd6b4729aa
1 file changed
+6 -28
+6 -28
View File
@@ -7,52 +7,30 @@ import (
)
type Routes struct {
innerMethods map[string]bool
allMethods map[string]bool
authUserMethods map[string]bool
innerMethods map[string]bool
}
func NewRoutes() *Routes {
return &Routes{
innerMethods: make(map[string]bool),
allMethods: make(map[string]bool),
authUserMethods: make(map[string]bool),
innerMethods: make(map[string]bool),
}
}
func (s *Routes) ReceiveRoutes(ctx context.Context, routes cluster.RoutingConfig) error {
newAddressMap := make(map[string]bool)
newInnerAddressMap := make(map[string]bool)
newAuthUserAddressMap := make(map[string]bool)
newInnerMethods := make(map[string]bool)
for _, backend := range routes {
if backend.Address.IP == "" || backend.Address.Port == "" || len(backend.Endpoints) == 0 {
continue
}
for _, v := range backend.Endpoints {
newAddressMap[v.Path] = true
if v.Inner {
newInnerAddressMap[v.Path] = true
}
if v.UserAuthRequired {
newAuthUserAddressMap[v.Path] = true
newInnerMethods[v.Path] = true
}
}
}
s.allMethods = newAddressMap
s.innerMethods = newInnerAddressMap
s.authUserMethods = newAuthUserAddressMap
s.innerMethods = newInnerMethods
return nil
}
func (s *Routes) IsAvailableMethod(path string) bool {
return s.allMethods[path]
}
func (s *Routes) IsAuthUserMethod(path string) bool {
return s.authUserMethods[path]
}
func (s *Routes) IsInnerMethod(path string) bool {
return s.innerMethods[path]
}