-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
57 lines (49 loc) · 1.04 KB
/
flags.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
package main
import (
"fmt"
"strconv"
"strings"
"github.com/ulysseses/raft"
)
type mapValue struct {
m *map[uint64]string
}
func (v *mapValue) String() string {
return "0,tcp://localhost:8080"
}
func (v *mapValue) Set(arg string) error {
*v.m = map[uint64]string{}
splits := strings.Split(arg, "|")
for _, split := range splits {
innerSplits := strings.Split(split, ",")
if len(innerSplits) != 2 {
return fmt.Errorf("key should be separated from value with a comma")
}
id, err := strconv.ParseUint(innerSplits[0], 10, 64)
if err != nil {
return err
}
addr := innerSplits[1]
(*v.m)[id] = addr
}
return nil
}
type consistencyValue struct {
c *raft.Consistency
}
func (v *consistencyValue) String() string {
return v.c.String()
}
func (v *consistencyValue) Set(arg string) error {
switch strings.ToLower(arg) {
case "lease":
*v.c = raft.ConsistencyLease
case "strict":
*v.c = raft.ConsistencyStrict
case "stale":
*v.c = raft.ConsistencyStale
default:
return fmt.Errorf("unknown consistency %s", arg)
}
return nil
}