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)
| 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. |
| 244 | func 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. |
| 271 | func (h *handler) invoke(method handlerMethod, accessPermissions []Permission, responsePermissions []Permission) error { |