MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / ParseKeyspace

Function ParseKeyspace

rest/handler.go:244–268  ·  view source on GitHub ↗

ParseKeyspace will return a db, scope and collection for a given '.' separated keyspace string. Returns nil for scope and/or collection if not present in the keyspace string.

(ks string)

Source from the content-addressed store, hash-verified

242// ParseKeyspace will return a db, scope and collection for a given '.' separated keyspace string.
243// Returns nil for scope and/or collection if not present in the keyspace string.
244func ParseKeyspace(ks string) (db string, scope, collection *string, err error) {
245 parts := strings.Split(ks, base.ScopeCollectionSeparator)
246 switch len(parts) {
247 case 1:
248 db = parts[0]
249 case 2:
250 db = parts[0]
251 collection = &parts[1]
252 case 3:
253 db = parts[0]
254 scope = &parts[1]
255 collection = &parts[2]
256 default:
257 return "", nil, nil, fmt.Errorf("unknown keyspace format: %q - expected 1-3 fields", ks)
258 }
259
260 // make sure all declared fields have stuff in them
261 if db == "" ||
262 collection != nil && *collection == "" ||
263 scope != nil && *scope == "" {
264 return "", nil, nil, fmt.Errorf("keyspace fields cannot be empty: %q", ks)
265 }
266
267 return db, scope, collection, nil
268}
269
270// Top-level handler call. It's passed a pointer to the specific method to run.
271func (h *handler) invoke(method handlerMethod, accessPermissions []Permission, responsePermissions []Permission) error {

Callers 10

getOIDCCallbackURLMethod · 0.85
getUserPayloadMethod · 0.85
getPayloadMethod · 0.85
Test_parseKeyspaceFunction · 0.85
Benchmark_parseKeyspaceFunction · 0.85
SetAdminChannelsMethod · 0.85
wrapRouterFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by 5

getUserPayloadMethod · 0.68
getPayloadMethod · 0.68
Test_parseKeyspaceFunction · 0.68
Benchmark_parseKeyspaceFunction · 0.68