package main import ( "encoding/json" "net/http" "imuslab.com/zoraxy/mod/utils" ) func HandleCountryDistrSummary(w http.ResponseWriter, r *http.Request) { requestClientCountry := map[string]int{} statisticCollector.DailySummary.RequestClientIp.Range(func(key, value interface{}) bool { //Get this client country of original clientIp := key.(string) //requestCount := value.(int) ci, err := geodbStore.ResolveCountryCodeFromIP(clientIp) if err != nil { return true } isoCode := ci.CountryIsoCode if isoCode == "" { isoCode = "Local" } uc, ok := requestClientCountry[isoCode] if !ok { //Create the counter requestClientCountry[isoCode] = 1 } else { requestClientCountry[isoCode] = uc + 1 } return true }) js, _ := json.Marshal(requestClientCountry) utils.SendJSONResponse(w, string(js)) }