@@ -102,7 +102,7 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
102102 }
103103 if strings .HasPrefix (line , "Name:" ) {
104104 parserOn = true
105- s := strings .TrimLeft (line , "Name: " )
105+ s := strings .TrimPrefix (line , "Name: " )
106106 s = strings .Join (strings .Fields (s ), " " )
107107 server .Database = s
108108 continue
@@ -111,7 +111,7 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
111111 continue
112112 }
113113 if strings .HasPrefix (line , "Cluster ID:" ) {
114- s := strings .TrimLeft (line , "Cluster ID:" )
114+ s := strings .TrimPrefix (line , "Cluster ID:" )
115115 s = strings .Join (strings .Fields (strings .TrimSpace (s )), " " )
116116 arr := strings .Split (s , " " )
117117 if len (arr ) != 2 {
@@ -124,7 +124,7 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
124124 }
125125 continue
126126 } else if strings .HasPrefix (line , "Server ID:" ) {
127- s := strings .TrimLeft (line , "Server ID:" )
127+ s := strings .TrimPrefix (line , "Server ID:" )
128128 s = strings .Join (strings .Fields (strings .TrimSpace (s )), " " )
129129 arr := strings .Split (s , " " )
130130 if len (arr ) != 2 {
@@ -137,12 +137,12 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
137137 }
138138 continue
139139 } else if strings .HasPrefix (line , "Address:" ) {
140- s := strings .TrimLeft (line , "Address:" )
140+ s := strings .TrimPrefix (line , "Address:" )
141141 s = strings .Join (strings .Fields (s ), " " )
142142 server .Address = s
143143 continue
144144 } else if strings .HasPrefix (line , "Status:" ) {
145- s := strings .TrimLeft (line , "Status:" )
145+ s := strings .TrimPrefix (line , "Status:" )
146146 s = strings .Join (strings .Fields (s ), " " )
147147 switch s {
148148 case "cluster member" :
@@ -152,7 +152,7 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
152152 }
153153 continue
154154 } else if strings .HasPrefix (line , "Role:" ) {
155- s := strings .TrimLeft (line , "Role:" )
155+ s := strings .TrimPrefix (line , "Role:" )
156156 s = strings .Join (strings .Fields (s ), " " )
157157 switch s {
158158 case "leader" :
@@ -166,29 +166,29 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
166166 }
167167 continue
168168 } else if strings .HasPrefix (line , "Term:" ) {
169- s := strings .TrimLeft (line , "Term:" )
169+ s := strings .TrimPrefix (line , "Term:" )
170170 s = strings .Join (strings .Fields (s ), " " )
171171 if term , err := strconv .ParseUint (s , 10 , 64 ); err == nil {
172172 server .Term = term
173173 }
174174 } else if strings .HasPrefix (line , "Leader:" ) {
175- s := strings .TrimLeft (line , "Leader:" )
175+ s := strings .TrimPrefix (line , "Leader:" )
176176 s = strings .Join (strings .Fields (s ), " " )
177177 if s == "self" {
178178 server .IsLeaderSelf = 1
179179 } else {
180180 server .IsLeaderSelf = 0
181181 }
182182 } else if strings .HasPrefix (line , "Vote:" ) {
183- s := strings .TrimLeft (line , "Vote:" )
183+ s := strings .TrimPrefix (line , "Vote:" )
184184 s = strings .Join (strings .Fields (s ), " " )
185185 if s == "self" {
186186 server .IsVotedSelf = 1
187187 } else {
188188 server .IsVotedSelf = 0
189189 }
190190 } else if strings .HasPrefix (line , "Log:" ) {
191- s := strings .TrimLeft (line , "Log:" )
191+ s := strings .TrimPrefix (line , "Log:" )
192192 s = strings .Join (strings .Fields (s ), " " )
193193 s = strings .TrimLeft (s , "[" )
194194 s = strings .TrimRight (s , "]" )
@@ -205,19 +205,19 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
205205 server .Log .High = i
206206 }
207207 } else if strings .HasPrefix (line , "Entries not yet committed:" ) {
208- s := strings .TrimLeft (line , "Entries not yet committed:" )
208+ s := strings .TrimPrefix (line , "Entries not yet committed:" )
209209 s = strings .Join (strings .Fields (s ), " " )
210210 if i , err := strconv .ParseUint (s , 10 , 64 ); err == nil {
211211 server .NotCommittedEntries = i
212212 }
213213 } else if strings .HasPrefix (line , "Entries not yet applied:" ) {
214- s := strings .TrimLeft (line , "Entries not yet applied:" )
214+ s := strings .TrimPrefix (line , "Entries not yet applied:" )
215215 s = strings .Join (strings .Fields (s ), " " )
216216 if i , err := strconv .ParseUint (s , 10 , 64 ); err == nil {
217217 server .NotAppliedEntries = i
218218 }
219219 } else if strings .HasPrefix (line , "Connections:" ) {
220- s := strings .TrimLeft (line , "Connections:" )
220+ s := strings .TrimPrefix (line , "Connections:" )
221221 s = strings .Join (strings .Fields (s ), " " )
222222 conns := strings .Split (strings .Join (strings .Fields (s ), " " ), " " )
223223 for _ , entry := range conns {
@@ -270,45 +270,41 @@ func (cli *OvnClient) GetAppClusteringInfo(db string) (ClusterState, error) {
270270 var peerMatchIndex uint64
271271 for _ , e := range arr {
272272 if strings .HasPrefix (e , "tcp:" ) || strings .HasPrefix (e , "ssl:" ) {
273- if isSelf != true {
273+ if ! isSelf {
274274 peerAddress = strings .TrimRight (e , ")" )
275275 }
276276 } else if strings .HasPrefix (e , "next_index=" ) {
277- nextIndex := strings .TrimLeft (e , "next_index=" )
277+ nextIndex := strings .TrimPrefix (e , "next_index=" )
278278 if i , err := strconv .ParseUint (nextIndex , 10 , 64 ); err == nil {
279- if isSelf == true {
279+ if isSelf {
280280 server .NextIndex = i
281281 } else {
282282 peerNextIndex = i
283283 }
284284 }
285285 } else if strings .HasPrefix (e , "match_index=" ) {
286- matchIndex := strings .TrimLeft (e , "match_index=" )
286+ matchIndex := strings .TrimPrefix (e , "match_index=" )
287287 if i , err := strconv .ParseUint (matchIndex , 10 , 64 ); err == nil {
288- if isSelf == true {
288+ if isSelf {
289289 server .MatchIndex = i
290290 } else {
291291 peerMatchIndex = i
292292 }
293293 }
294- } else {
295- // do nothing
296294 }
297- }
298- if isSelf != true {
299- if _ , exists := server .Peers [peerID ]; ! exists {
300- peer := ClusterPeer {}
301- peer .ID = peerID
302- server .Peers [peerID ] = & peer
295+ if ! isSelf {
296+ if _ , exists := server .Peers [peerID ]; ! exists {
297+ peer := ClusterPeer {}
298+ peer .ID = peerID
299+ server .Peers [peerID ] = & peer
300+ }
301+ peer := server .Peers [peerID ]
302+ peer .NextIndex = peerNextIndex
303+ peer .MatchIndex = peerMatchIndex
304+ peer .Address = peerAddress
303305 }
304- peer := server .Peers [peerID ]
305- peer .NextIndex = peerNextIndex
306- peer .MatchIndex = peerMatchIndex
307- peer .Address = peerAddress
306+ continue
308307 }
309- continue
310- } else {
311- // do nothing
312308 }
313309 }
314310 //spew.Dump(server)
0 commit comments