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) + +}