Skip to content

Commit bcb136a

Browse files
chore: make main method the first method in main.go
1 parent 46be896 commit bcb136a

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

main.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ var (
4040
lastServer = ""
4141
)
4242

43+
func main() {
44+
flag.Parse()
45+
connectZK(*server)
46+
47+
zkCmds := flag.Args()
48+
if zkCmds == nil || len(zkCmds) == 0 {
49+
loop()
50+
} else {
51+
// one time command line
52+
err := execZkCmd(zkconn.con, zkCmds[0], zkCmds[1:])
53+
if err != nil {
54+
fmt.Println(err)
55+
os.Exit(1)
56+
} else {
57+
os.Exit(0)
58+
}
59+
}
60+
}
61+
4362
func connectZK(address string) {
4463
if zkconn.con != nil && zkconn.con.State() == zk.StateHasSession {
4564
//close existed connection first
@@ -83,25 +102,6 @@ func connectZK(address string) {
83102
}
84103
}
85104

86-
func main() {
87-
flag.Parse()
88-
connectZK(*server)
89-
90-
zkCmds := flag.Args()
91-
if zkCmds == nil || len(zkCmds) == 0 {
92-
loop()
93-
} else {
94-
// one time command line
95-
err := execZkCmd(zkconn.con, zkCmds[0], zkCmds[1:])
96-
if err != nil {
97-
fmt.Println(err)
98-
os.Exit(1)
99-
} else {
100-
os.Exit(0)
101-
}
102-
}
103-
}
104-
105105
func isConnected(con *zk.Conn) bool {
106106
return con.State() == zk.StateHasSession
107107
}

0 commit comments

Comments
 (0)