MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetNameParentTokens

Function GetNameParentTokens

action/common/resource_name.go:38–52  ·  view source on GitHub ↗

GetNameParentTokens returns the tokens from a resource name.

(name string, tokenPrefixes ...string)

Source from the content-addressed store, hash-verified

36
37// GetNameParentTokens returns the tokens from a resource name.
38func GetNameParentTokens(name string, tokenPrefixes ...string) ([]string, error) {
39 parts := strings.Split(name, "/")
40 if len(parts) != 2*len(tokenPrefixes) {
41 return nil, errors.Errorf("invalid request %q", name)
42 }
43
44 var tokens []string
45 for i, tokenPrefix := range tokenPrefixes {
46 if fmt.Sprintf("%s/", parts[2*i]) != tokenPrefix {
47 return nil, errors.Errorf("invalid prefix %q in request %q", tokenPrefix, name)
48 }
49 tokens = append(tokens, parts[2*i+1])
50 }
51 return tokens, nil
52}

Callers 2

GetInstanceDatabaseIDFunction · 0.70

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected