MCPcopy
hub / github.com/keploy/keploy / relToAny

Function relToAny

utils/grpc.go:234–243  ·  view source on GitHub ↗

relToAny returns an import-style path (forward slashes) for abs under any root; "" if none match.

(abs string, roots []string)

Source from the content-addressed store, hash-verified

232
233// relToAny returns an import-style path (forward slashes) for abs under any root; "" if none match.
234func relToAny(abs string, roots []string) string {
235 abs = filepath.Clean(abs)
236 for _, r := range roots {
237 r = filepath.Clean(r)
238 if rel, err := filepath.Rel(r, abs); err == nil && !strings.HasPrefix(rel, "..") && !strings.HasPrefix(filepath.ToSlash(rel), "../") {
239 return filepath.ToSlash(rel)
240 }
241 }
242 return ""
243}
244
245// deriveProtoDirFromPath extracts the package from a gRPC path and searches protoInclude roots
246// for a matching directory. This enables automatic proto directory resolution for multi-service

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected