-
Notifications
You must be signed in to change notification settings - Fork 124
/
versions.go
37 lines (30 loc) · 931 Bytes
/
versions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package minion
import (
"context"
"fmt"
"github.com/twmb/franz-go/pkg/kerr"
"github.com/twmb/franz-go/pkg/kmsg"
"github.com/twmb/franz-go/pkg/kversion"
)
func (s *Service) GetClusterVersion(ctx context.Context) (string, error) {
res, err := s.GetAPIVersions(ctx)
if err != nil {
return "", err
}
versions := kversion.FromApiVersionsResponse(res)
return versions.VersionGuess(), nil
}
func (s *Service) GetAPIVersions(ctx context.Context) (*kmsg.ApiVersionsResponse, error) {
versionsReq := kmsg.NewApiVersionsRequest()
versionsReq.ClientSoftwareName = "kminion"
versionsReq.ClientSoftwareVersion = "v2"
res, err := versionsReq.RequestWith(ctx, s.client)
if err != nil {
return nil, fmt.Errorf("failed to request api versions: %w", err)
}
err = kerr.ErrorForCode(res.ErrorCode)
if err != nil {
return nil, fmt.Errorf("failed to request api versions. Inner kafka error: %w", err)
}
return res, nil
}