github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/deletegroups.go (about) 1 package kafka 2 3 import ( 4 "context" 5 "fmt" 6 "net" 7 "time" 8 9 "github.com/segmentio/kafka-go/protocol/deletegroups" 10 ) 11 12 // DeleteGroupsRequest represents a request sent to a kafka broker to delete 13 // consumer groups. 14 type DeleteGroupsRequest struct { 15 // Address of the kafka broker to send the request to. 16 Addr net.Addr 17 18 // Identifiers of groups to delete. 19 GroupIDs []string 20 } 21 22 // DeleteGroupsResponse represents a response from a kafka broker to a consumer group 23 // deletion request. 24 type DeleteGroupsResponse struct { 25 // The amount of time that the broker throttled the request. 26 Throttle time.Duration 27 28 // Mapping of group ids to errors that occurred while attempting to delete those groups. 29 // 30 // The errors contain the kafka error code. Programs may use the standard 31 // errors.Is function to test the error against kafka error codes. 32 Errors map[string]error 33 } 34 35 // DeleteGroups sends a delete groups request and returns the response. The request is sent to the group coordinator of the first group 36 // of the request. All deleted groups must be managed by the same group coordinator. 37 func (c *Client) DeleteGroups( 38 ctx context.Context, 39 req *DeleteGroupsRequest, 40 ) (*DeleteGroupsResponse, error) { 41 m, err := c.roundTrip(ctx, req.Addr, &deletegroups.Request{ 42 GroupIDs: req.GroupIDs, 43 }) 44 if err != nil { 45 return nil, fmt.Errorf("kafka.(*Client).DeleteGroups: %w", err) 46 } 47 48 r := m.(*deletegroups.Response) 49 50 ret := &DeleteGroupsResponse{ 51 Throttle: makeDuration(r.ThrottleTimeMs), 52 Errors: make(map[string]error, len(r.Responses)), 53 } 54 55 for _, t := range r.Responses { 56 ret.Errors[t.GroupID] = makeError(t.ErrorCode, "") 57 } 58 59 return ret, nil 60 }