diff --git a/dip.go b/dip.go index 07390a5..03a3323 100644 --- a/dip.go +++ b/dip.go @@ -75,35 +75,33 @@ func (group *DIPGroup) Choose(addr string) { } else { i := 0 - for ; i < 3; i++ { + for ; i < 2; i++ { imokURL := "http://" + dhost.Host + ":8800/pppoe/imok" - if _, err := requests.NewSession().Get(imokURL).Execute(); err != nil { + ses := requests.NewSession() + ses.SetConfig(requests.CRequestTimeout, 4) + if _, err := ses.Get(imokURL).Execute(); err != nil { log.Println(err) - + if i == 2 { + // 下个需要切换的DHost错误 + group.Current.ActiveTime = now + 15 + delete(group.Ready, ip) + return // 不执行下面的 切换操作 for ip, dhost := range group.Ready + } } else { // 如果ping 通下个切换的主机就切换 - for ii := 0; ii < 3; ii++ { restartURL := "http://" + group.Current.Host + ":8800/pppoe/restart" - if _, err := requests.NewSession().Get(restartURL).Execute(); err != nil { + if _, err := ses.Get(restartURL).Execute(); err != nil { log.Println(err) } else { break // 可以切换 ii := 0; ii < 3; ii++ } } - break // for ; i < 3; i++ { - } } - if i == 3 { - // 下个需要切换的DHost错误 - delete(group.Ready, ip) - continue // 不执行下面的 切换操作 for ip, dhost := range group.Ready - } - } group.Current = dhost diff --git a/switch.go b/switch.go index ae6b775..26c4bf9 100644 --- a/switch.go +++ b/switch.go @@ -201,7 +201,6 @@ func (swi *Switch) switchActives(w http.ResponseWriter, req *http.Request) { for addr, group := range swi.Worker.ForLoop { addrmap := make(map[string]interface{}) - content[addr] = addrmap isappend := int64(0) var hosts []string @@ -212,6 +211,7 @@ func (swi *Switch) switchActives(w http.ResponseWriter, req *http.Request) { hosts = append(hosts, dhost.Host) } if isappend > 1 { + content[addr] = addrmap addrmap["group"] = hosts addrmap["city"] = group.City }