-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
48 lines (36 loc) · 1.02 KB
/
config.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
package main
import (
"strings"
"github.com/pkg/errors"
)
type Config struct {
DataSet string
ConfigSet string
Mongos string
Retry int
Wait int
Port int
}
// ReplicaSet format <replicaSetName>/data1:27017,data2:27017,data3:27017
func ParseReplicaSet(definition string) (string, []string, error) {
parts := strings.Split(definition, "/")
if len(parts) != 2 {
return "", nil, errors.New("Invalid ReplicaSet definition, expected <replicaSetName>/data1:27017,data2:27017,data3:27017")
}
replSetName := parts[0]
members := strings.Split(parts[1], ",")
if len(members) < 3 {
return "", nil, errors.New("Invalid ReplicaSet definition, a minimum of 3 members required")
}
return replSetName, members, nil
}
func ParseMongos(definition string) ([]string, error) {
list := strings.Split(definition, ",")
for _, mongos := range list {
parts := strings.Split(mongos, ":")
if len(parts) != 2 {
return nil, errors.Errorf("%v invalid format, expected <HOST>:<PORT>", mongos)
}
}
return list, nil
}