Merge branch 'feature/addApiForMitm' into 'develop'

增加真机mitm用allProxies接口

See merge request mt-data/ipcenter!3
This commit is contained in:
wangchaofeng 2019-03-14 14:47:46 +08:00
commit 1f84d5ec79

View File

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