From 5882bab2f3a32fd24f2a44fdb356a2f8b97d5159 Mon Sep 17 00:00:00 2001 From: chiufung <1012137875@qq.com> Date: Thu, 14 Mar 2019 14:46:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9C=9F=E6=9C=BAmitm?= =?UTF-8?q?=E7=94=A8allProxies=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- switch.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/switch.go b/switch.go index 2aa12ec..ae6b775 100644 --- a/switch.go +++ b/switch.go @@ -44,6 +44,7 @@ func NewSwitch() *Switch { http.HandleFunc("/ippool/switch/imactive", swi.imActive) http.HandleFunc("/ippool/switch/update", swi.updateActives) http.HandleFunc("/ippool/switch/actives", swi.switchActives) + http.HandleFunc("/ippool/switch/allproxies", swi.allProxies) return &swi } @@ -221,3 +222,32 @@ func (swi *Switch) switchActives(w http.ResponseWriter, req *http.Request) { ErrorLog(err) } + +func (swi *Switch) allProxies(w http.ResponseWriter, req *http.Request) { + defer req.Body.Close() + + swi.Worker.Mutex.Lock() + defer swi.Worker.Mutex.Unlock() + + now := time.Now().Unix() + + content := make(map[string]map[string]interface{}) + for addr, group := range swi.Worker.ForLoop { + + addrmap := make(map[string]interface{}) + content[addr] = addrmap + + isappend := int64(0) + var hosts []string + for _, dhost := range group.Group { + hosts = append(hosts, dhost.Host) + } + addrmap["group"] = hosts + addrmap["city"] = group.City + } + jdata, err := json.Marshal(content) + ErrorLog(err) + _, err = w.Write(jdata) + ErrorLog(err) + +}