-
Notifications
You must be signed in to change notification settings - Fork 5
/
flag.go
67 lines (56 loc) · 1.45 KB
/
flag.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
63
64
65
66
67
package myflag
import (
"encoding/base64"
"flag"
"fmt"
)
type Args struct {
OpType string
ClusterName string
ForceFailOver string
}
type MetaDBInfo struct {
MetaUser string
MetaPasswd []byte
MetaDBName string
MetaHost string
MetaPort int
MetaNetWork string
MetaEncodePasswd string
MetaDsn string
}
type OrcheMapping struct {
Id string
DbClusterName string
}
var (
a Args
m MetaDBInfo
o OrcheMapping
)
const (
ver = "-*-==================================== orch_ha version 1.0 ====================================-*-"
exam = `Example:
./orch_ha --OpType=[precheck|switchover] --ClusterName=[cluster name] [--force]
`
)
func NewFlag() (*Args, error) {
flag.StringVar(&a.OpType, "OpType", "none", "operation type(precheck, switchover). default none")
flag.StringVar(&a.ClusterName, "ClusterName", "none", "input cluster name. default none")
forceFailover := flag.Bool("force", false, "force failover.")
flag.Parse()
if a.OpType == "none" || a.ClusterName == "none" {
fmt.Printf("\n")
fmt.Println(ver)
fmt.Printf("\n")
fmt.PrintDefaults()
fmt.Printf("\n")
fmt.Println(exam)
}
return &Args{OpType: a.OpType, ClusterName: a.ClusterName, ForceFailOver: *forceFailover}, nil
}
func NewMetaInfo() (*MetaDBInfo, error) {
m.MetaEncodePasswd = "xxxx"
m.MetaPasswd, _ = base64.StdEncoding.DecodeString(m.MetaEncodePasswd)
return &MetaDBInfo{MetaDsn: m.MetaDsn}, nil
}