ResolveOperationWithMetadata will find an operation that has the matching metadata
(key string, value string)
| 37 | |
| 38 | // ResolveOperationWithMetadata will find an operation that has the matching metadata |
| 39 | func (e *CachedEntityBase[SnapT, OpT]) ResolveOperationWithMetadata(key string, value string) (entity.Id, error) { |
| 40 | e.mu.RLock() |
| 41 | defer e.mu.RUnlock() |
| 42 | // preallocate but empty |
| 43 | matching := make([]entity.Id, 0, 5) |
| 44 | |
| 45 | for _, op := range e.entity.Operations() { |
| 46 | opValue, ok := op.GetMetadata(key) |
| 47 | if ok && value == opValue { |
| 48 | matching = append(matching, op.Id()) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | if len(matching) == 0 { |
| 53 | return "", ErrNoMatchingOp |
| 54 | } |
| 55 | |
| 56 | if len(matching) > 1 { |
| 57 | return "", entity.NewErrMultipleMatch("operation", matching) |
| 58 | } |
| 59 | |
| 60 | return matching[0], nil |
| 61 | } |
| 62 | |
| 63 | func (e *CachedEntityBase[SnapT, OpT]) Validate() error { |
| 64 | e.mu.RLock() |
no test coverage detected