MSP-625 reimplement routes
This commit is contained in:
1 parent
d9605304d2
commit
9307c80b2b
2 files changed
+58
-35
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/integration-system/isp-kit/cluster"
|
||||
)
|
||||
|
||||
type Routes struct {
|
||||
innerMethods map[string]bool
|
||||
allMethods map[string]bool
|
||||
authUserMethods map[string]bool
|
||||
}
|
||||
|
||||
func NewRoutes() *Routes {
|
||||
return &Routes{
|
||||
innerMethods: make(map[string]bool),
|
||||
allMethods: make(map[string]bool),
|
||||
authUserMethods: 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)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
s.allMethods = newAddressMap
|
||||
s.innerMethods = newInnerAddressMap
|
||||
s.authUserMethods = newAuthUserAddressMap
|
||||
|
||||
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]
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-lib/v2/structure"
|
||||
)
|
||||
|
||||
var (
|
||||
InnerMethods = make(map[string]bool)
|
||||
AllMethods = make(map[string]bool)
|
||||
AuthUserMethods = make(map[string]bool)
|
||||
)
|
||||
|
||||
func InitRoutes(configs structure.RoutingConfig) {
|
||||
newAddressMap := make(map[string]bool)
|
||||
newInnerAddressMap := make(map[string]bool)
|
||||
newAuthUserAddressMap := make(map[string]bool)
|
||||
for i := range configs {
|
||||
backend := &configs[i]
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
AllMethods = newAddressMap
|
||||
InnerMethods = newInnerAddressMap
|
||||
AuthUserMethods = newAuthUserAddressMap
|
||||
}
|
||||
Reference in new issue
Block a user