GetGroup gets a group.
(ctx context.Context, find *FindGroupMessage)
| 76 | |
| 77 | // GetGroup gets a group. |
| 78 | func (s *Store) GetGroup(ctx context.Context, find *FindGroupMessage) (*GroupMessage, error) { |
| 79 | if find.Email != nil && find.Workspace != "" { |
| 80 | if v, ok := s.groupCache.Get(getGroupCacheKey(find.Workspace, &GroupMessage{Email: *find.Email})); ok && s.enableCache { |
| 81 | return v, nil |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | groups, err := s.ListGroups(ctx, find) |
| 86 | if err != nil { |
| 87 | return nil, err |
| 88 | } |
| 89 | |
| 90 | if len(groups) == 0 { |
| 91 | return nil, nil |
| 92 | } else if len(groups) > 1 { |
| 93 | return nil, &common.Error{Code: common.Conflict, Err: errors.Errorf("found %d groups with filter %+v, expect 1", len(groups), find)} |
| 94 | } |
| 95 | return groups[0], nil |
| 96 | } |
| 97 | |
| 98 | // ListGroups list all groups. |
| 99 | func (s *Store) ListGroups(ctx context.Context, find *FindGroupMessage) ([]*GroupMessage, error) { |
no test coverage detected