@@ -16,13 +16,18 @@ type DescribeConsumerGroupsResponse struct {
1616 Groups * kmsg.DescribeGroupsResponse
1717}
1818
19- func (s * Service ) listConsumerGroupsCached (ctx context.Context ) (* kmsg.ListGroupsResponse , error ) {
20- key := "list-consumer-groups"
19+ type GroupsInfo struct {
20+ AllowedGroups * kmsg.ListGroupsResponse
21+ AllGroupsCount int
22+ }
23+
24+ func (s * Service ) listConsumerGroupsCached (ctx context.Context ) (* GroupsInfo , error ) {
25+ keyAllowedGroups := "list-consumer-groups"
2126
22- if cachedRes , exists := s .getCachedItem (key ); exists {
23- return cachedRes .(* kmsg. ListGroupsResponse ), nil
27+ if cachedRes , exists := s .getCachedItem (keyAllowedGroups ); exists {
28+ return cachedRes .(* GroupsInfo ), nil
2429 }
25- res , err , _ := s .requestGroup .Do (key , func () (interface {}, error ) {
30+ groups , err , _ := s .requestGroup .Do (keyAllowedGroups , func () (interface {}, error ) {
2631 res , err := s .listConsumerGroups (ctx )
2732 if err != nil {
2833 return nil , err
@@ -34,15 +39,19 @@ func (s *Service) listConsumerGroupsCached(ctx context.Context) (*kmsg.ListGroup
3439 }
3540 }
3641 res .Groups = allowedGroups
37- s .setCachedItem (key , res , 120 * time .Second )
42+ groups := & GroupsInfo {
43+ AllGroupsCount : len (res .Groups ),
44+ AllowedGroups : res ,
45+ }
46+ s .setCachedItem (keyAllowedGroups , groups , 120 * time .Second )
3847
39- return res , nil
48+ return groups , nil
4049 })
4150 if err != nil {
4251 return nil , err
4352 }
4453
45- return res .(* kmsg. ListGroupsResponse ), nil
54+ return groups .(* GroupsInfo ), nil
4655}
4756
4857func (s * Service ) listConsumerGroups (ctx context.Context ) (* kmsg.ListGroupsResponse , error ) {
@@ -59,14 +68,14 @@ func (s *Service) listConsumerGroups(ctx context.Context) (*kmsg.ListGroupsRespo
5968 return res , nil
6069}
6170
62- func (s * Service ) DescribeConsumerGroups (ctx context.Context ) ([]DescribeConsumerGroupsResponse , error ) {
71+ func (s * Service ) DescribeConsumerGroups (ctx context.Context ) ([]DescribeConsumerGroupsResponse , int , error ) {
6372 listRes , err := s .listConsumerGroupsCached (ctx )
6473 if err != nil {
65- return nil , err
74+ return nil , - 1 , err
6675 }
6776
68- groupIDs := make ([]string , len (listRes .Groups ))
69- for i , group := range listRes .Groups {
77+ groupIDs := make ([]string , len (listRes .AllowedGroups . Groups ))
78+ for i , group := range listRes .AllowedGroups . Groups {
7079 groupIDs [i ] = group .Group
7180 }
7281
@@ -90,6 +99,5 @@ func (s *Service) DescribeConsumerGroups(ctx context.Context) ([]DescribeConsume
9099 Groups : res ,
91100 })
92101 }
93-
94- return describedGroups , nil
102+ return describedGroups , listRes .AllGroupsCount , nil
95103}
0 commit comments