GetObjectByParentAndName finds a child element by name and its parent id
(parent, name string)
| 168 | |
| 169 | // GetObjectByParentAndName finds a child element by name and its parent id |
| 170 | func (c *Cache) GetObjectByParentAndName(parent, name string) (object *APIObject, err error) { |
| 171 | Log.Tracef("Getting object %v in parent %v", name, parent) |
| 172 | |
| 173 | c.db.View(func(tx *bolt.Tx) error { |
| 174 | // Look up object id in parent-name index |
| 175 | b := tx.Bucket(bParents) |
| 176 | v := b.Get([]byte(parent + "/" + name)) |
| 177 | if nil == v { |
| 178 | return nil |
| 179 | } |
| 180 | |
| 181 | // Fetch object for given id |
| 182 | object, err = boltGetObject(tx, string(v)) |
| 183 | return nil |
| 184 | }) |
| 185 | if nil != err { |
| 186 | return nil, err |
| 187 | } |
| 188 | |
| 189 | if object == nil { |
| 190 | return nil, fmt.Errorf("Could not find object with name %v in parent %v", name, parent) |
| 191 | } |
| 192 | |
| 193 | Log.Tracef("Got object from cache %v", object) |
| 194 | return object, nil |
| 195 | } |
| 196 | |
| 197 | // DeleteObject deletes an object by id |
| 198 | func (c *Cache) DeleteObject(id string) error { |
no test coverage detected