forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 9
/
version.go
62 lines (49 loc) · 1.1 KB
/
version.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package kafka
import (
"fmt"
"github.com/Shopify/sarama"
)
type Version struct {
String string
}
var (
minVersion = sarama.V0_8_2_0
kafkaVersions = map[string]sarama.KafkaVersion{
"": sarama.V0_8_2_0,
"0.8.2.0": sarama.V0_8_2_0,
"0.8.2.1": sarama.V0_8_2_1,
"0.8.2.2": sarama.V0_8_2_2,
"0.8.2": sarama.V0_8_2_2,
"0.8": sarama.V0_8_2_2,
"0.9.0.0": sarama.V0_9_0_0,
"0.9.0.1": sarama.V0_9_0_1,
"0.9.0": sarama.V0_9_0_1,
"0.9": sarama.V0_9_0_1,
"0.10.0.0": sarama.V0_10_0_0,
"0.10.0.1": sarama.V0_10_0_1,
"0.10.0": sarama.V0_10_0_1,
"0.10.1.0": sarama.V0_10_1_0,
"0.10.1": sarama.V0_10_1_0,
"0.10": sarama.V0_10_1_0,
}
)
func (v *Version) Validate() error {
if _, ok := kafkaVersions[v.String]; !ok {
return fmt.Errorf("unknown/unsupported kafka vesion '%v'", v.String)
}
return nil
}
func (v *Version) Unpack(s string) error {
tmp := Version{s}
if err := tmp.Validate(); err != nil {
return err
}
*v = tmp
return nil
}
func (v *Version) get() sarama.KafkaVersion {
if v, ok := kafkaVersions[v.String]; ok {
return v
}
return minVersion
}