handlers.go 844 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "imuslab.com/zoraxy/mod/utils"
  6. )
  7. func HandleCountryDistrSummary(w http.ResponseWriter, r *http.Request) {
  8. requestClientCountry := map[string]int{}
  9. statisticCollector.DailySummary.RequestClientIp.Range(func(key, value interface{}) bool {
  10. //Get this client country of original
  11. clientIp := key.(string)
  12. //requestCount := value.(int)
  13. ci, err := geodbStore.ResolveCountryCodeFromIP(clientIp)
  14. if err != nil {
  15. return true
  16. }
  17. isoCode := ci.CountryIsoCode
  18. if isoCode == "" {
  19. isoCode = "Local"
  20. }
  21. uc, ok := requestClientCountry[isoCode]
  22. if !ok {
  23. //Create the counter
  24. requestClientCountry[isoCode] = 1
  25. } else {
  26. requestClientCountry[isoCode] = uc + 1
  27. }
  28. return true
  29. })
  30. js, _ := json.Marshal(requestClientCountry)
  31. utils.SendJSONResponse(w, string(js))
  32. }