MCPcopy Index your code
hub / github.com/cloudfoundry/cli / CreatePath

Method CreatePath

api/cloudcontroller/ccv3/internal/routing.go:81–101  ·  view source on GitHub ↗

CreatePath combines the route's path pattern with a Params map to produce a valid path.

(params Params)

Source from the content-addressed store, hash-verified

79// CreatePath combines the route's path pattern with a Params map
80// to produce a valid path.
81func (r Route) CreatePath(params Params) (string, error) {
82 components := strings.Split(r.Path, "/")
83 for i, c := range components {
84 if len(c) == 0 {
85 continue
86 }
87 if c[0] == ':' {
88 val, ok := params[c[1:]]
89 if !ok {
90 return "", fmt.Errorf("missing param %s", c)
91 }
92 components[i] = val
93 }
94 }
95
96 u, err := url.Parse(strings.Join(components, "/"))
97 if err != nil {
98 return "", err
99 }
100 return u.String(), nil
101}
102
103// Router combines route and resource information in order to generate HTTP
104// requests.

Callers 2

routing_test.goFile · 0.45
CreateRequestMethod · 0.45

Calls 2

ParseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected