123456789101112131415161718192021222324252627282930313233343536373839 |
- 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 == "" {
- //local or reserved addr
- 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))
- }
|