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

Method selectBackend

pkg/backends/composite.go:41–54  ·  view source on GitHub ↗

selectBackend 根据路径选择后端 返回后端和剥离前缀后的路径

(path string)

Source from the content-addressed store, hash-verified

39// selectBackend 根据路径选择后端
40// 返回后端和剥离前缀后的路径
41func (b *CompositeBackend) selectBackend(path string) (BackendProtocol, string) {
42 for _, route := range b.routes {
43 if strippedPath, found := strings.CutPrefix(path, route.Prefix); found {
44 // 确保路径以 / 开头
45 if strippedPath == "" {
46 strippedPath = "/"
47 } else if !strings.HasPrefix(strippedPath, "/") {
48 strippedPath = "/" + strippedPath
49 }
50 return route.Backend, strippedPath
51 }
52 }
53 return b.defaultBackend, path
54}
55
56// backendWithPrefix 后端及其路由前缀
57type backendWithPrefix struct {

Callers 3

ReadMethod · 0.95
WriteMethod · 0.95
EditMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected