...
1
2
3
4
5
6
7 package unified
8
9 import (
10 "fmt"
11 "strconv"
12 "strings"
13
14 "go.mongodb.org/mongo-driver/mongo/integration/mtest"
15 )
16
17 var (
18 supportedSchemaVersions = map[int]string{
19 1: "1.17",
20 }
21 )
22
23
24 func checkSchemaVersion(version string) error {
25
26
27
28 parts := strings.Split(version, ".")
29 if len(parts) == 0 {
30 return fmt.Errorf("error splitting schema version %q into parts", version)
31 }
32
33 majorVersion, err := strconv.Atoi(parts[0])
34 if err != nil {
35 return fmt.Errorf("error converting major version component %q to an integer: %v", parts[0], err)
36 }
37
38
39
40 supportedVersion, ok := supportedSchemaVersions[majorVersion]
41 if !ok {
42 return fmt.Errorf("major version %d not supported", majorVersion)
43 }
44 if mtest.CompareServerVersions(supportedVersion, version) < 0 {
45 return fmt.Errorf(
46 "latest version supported for major version %d is %q, which is incompatible with specified version %q",
47 majorVersion, supportedVersion, version,
48 )
49 }
50 return nil
51 }
52
View as plain text