MCPcopy Create free account
hub / github.com/astercloud/aster / NewCompositeBackend

Function NewCompositeBackend

pkg/backends/composite.go:25–37  ·  view source on GitHub ↗

NewCompositeBackend 创建 CompositeBackend 实例

(defaultBackend BackendProtocol, routes []RouteConfig)

Source from the content-addressed store, hash-verified

23
24// NewCompositeBackend 创建 CompositeBackend 实例
25func NewCompositeBackend(defaultBackend BackendProtocol, routes []RouteConfig) *CompositeBackend {
26 // 按前缀长度降序排序,确保优先匹配最长前缀
27 sortedRoutes := make([]RouteConfig, len(routes))
28 copy(sortedRoutes, routes)
29 sort.Slice(sortedRoutes, func(i, j int) bool {
30 return len(sortedRoutes[i].Prefix) > len(sortedRoutes[j].Prefix)
31 })
32
33 return &CompositeBackend{
34 defaultBackend: defaultBackend,
35 routes: sortedRoutes,
36 }
37}
38
39// selectBackend 根据路径选择后端
40// 返回后端和剥离前缀后的路径

Callers 4

Phase4IntegrationExampleFunction · 0.92
mainFunction · 0.92

Calls 1

copyFunction · 0.85