forked from couchbase/cbgt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
49 lines (42 loc) · 1.08 KB
/
util.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
package cbgt
import (
"bytes"
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"strconv"
"strings"
)
func computeMD5(payload []byte) (string, error) {
hash := md5.New()
if _, err := io.Copy(hash, bytes.NewReader(payload)); err != nil {
return "", err
}
return hex.EncodeToString(hash.Sum(nil)), nil
}
// VersionReader is an interface to be implemented by the
// configuration providers who supports the verification of
// homogeneousness of the cluster before performing certain
// Key/Values updates related to the cluster status
type VersionReader interface {
// ClusterVersion retrieves the cluster
// compatibility information from the ns_server
ClusterVersion() (uint64, error)
}
func CompatibilityVersion(version string) (uint64, error) {
eVersion := uint64(1)
xa := strings.Split(version, ".")
if len(xa) < 2 {
return eVersion, fmt.Errorf("invalid version")
}
majVersion, err := strconv.Atoi(xa[0])
if err != nil {
return eVersion, err
}
minVersion, err := strconv.Atoi(xa[1])
if err != nil {
return eVersion, err
}
return uint64(65536*majVersion + minVersion), nil
}