github.com/nxtrace/NTrace-core@v1.3.1-0.20240513132635-39169291e8c9/ipgeo/ipgeo.go (about)

     1  package ipgeo
     2  
     3  import (
     4  	"strings"
     5  	"time"
     6  )
     7  
     8  type IPGeoData struct {
     9  	IP        string              `json:"ip"`
    10  	Asnumber  string              `json:"asnumber"`
    11  	Country   string              `json:"country"`
    12  	CountryEn string              `json:"country_en"`
    13  	Prov      string              `json:"prov"`
    14  	ProvEn    string              `json:"prov_en"`
    15  	City      string              `json:"city"`
    16  	CityEn    string              `json:"city_en"`
    17  	District  string              `json:"district"`
    18  	Owner     string              `json:"owner"`
    19  	Isp       string              `json:"isp"`
    20  	Domain    string              `json:"domain"`
    21  	Whois     string              `json:"whois"`
    22  	Lat       float64             `json:"lat"`
    23  	Lng       float64             `json:"lng"`
    24  	Prefix    string              `json:"prefix"`
    25  	Router    map[string][]string `json:"router"`
    26  	Source    string              `json:"source"`
    27  }
    28  
    29  type Source = func(ip string, timeout time.Duration, lang string, maptrace bool) (*IPGeoData, error)
    30  
    31  func GetSource(s string) Source {
    32  	switch strings.ToUpper(s) {
    33  	case "DN42":
    34  		return DN42
    35  	case "LEOMOEAPI":
    36  		return LeoIP
    37  	case "IP.SB":
    38  		return IPSB
    39  	case "IPINSIGHT":
    40  		return IPInSight
    41  	case "IPAPI.COM":
    42  		return IPApiCom
    43  	case "IP-API.COM":
    44  		return IPApiCom
    45  	case "IPINFO":
    46  		return IPInfo
    47  	case "IP2REGION":
    48  		return IP2Region
    49  	case "IPINFOLOCAL":
    50  		return IPInfoLocal
    51  	case "CHUNZHEN":
    52  		return Chunzhen
    53  	case "DISABLE-GEOIP":
    54  		return disableGeoIP
    55  	default:
    56  		return LeoIP
    57  	}
    58  }
    59  
    60  func disableGeoIP(string, time.Duration, string, bool) (*IPGeoData, error) {
    61  	return &IPGeoData{}, nil
    62  }