MCPcopy Create free account
hub / github.com/goadesign/goa / FullPaths

Method FullPaths

expr/http_service.go:110–147  ·  view source on GitHub ↗

FullPaths computes the base paths to the service endpoints concatenating the API and parent service base paths as needed.

()

Source from the content-addressed store, hash-verified

108// FullPaths computes the base paths to the service endpoints concatenating the
109// API and parent service base paths as needed.
110func (svc *HTTPServiceExpr) FullPaths() []string {
111 if len(svc.Paths) == 0 {
112 return []string{path.Join(svc.Root.Path)}
113 }
114 var paths []string
115 for _, p := range svc.Paths {
116 if strings.HasPrefix(p, "//") {
117 paths = append(paths, httppath.Clean(p))
118 continue
119 }
120 var basePaths []string
121 if p := svc.Parent(); p != nil {
122 if ca := p.CanonicalEndpoint(); ca != nil {
123 if routes := ca.Routes; len(routes) > 0 {
124 // Note: all these tests should be true at code
125 // generation time as DSL validation makes sure
126 // that parent services have a canonical path.
127 fullPaths := routes[0].FullPaths()
128 basePaths = make([]string, len(fullPaths))
129 for i, p := range fullPaths {
130 basePaths[i] = path.Join(p)
131 }
132 }
133 }
134 } else {
135 basePaths = []string{svc.Root.Path}
136 }
137 for _, base := range basePaths {
138 v := httppath.Clean(path.Join(base, p))
139 // path has trailing slash
140 if strings.HasSuffix(p, "/") {
141 v += "/"
142 }
143 paths = append(paths, v)
144 }
145 }
146 return paths
147}
148
149// Parent returns the parent service if any, nil otherwise.
150func (svc *HTTPServiceExpr) Parent() *HTTPServiceExpr {

Callers

nothing calls this directly

Calls 2

ParentMethod · 0.95
CanonicalEndpointMethod · 0.80

Tested by

no test coverage detected