diff --git a/const.go b/const.go index c9136ed..adc4612 100644 --- a/const.go +++ b/const.go @@ -1,3 +1,3 @@ package goip -const Version = "1.0.31" +const Version = "1.0.32" diff --git a/geoip/client.go b/geoip/client.go index 9ff61de..1e220fe 100644 --- a/geoip/client.go +++ b/geoip/client.go @@ -5,20 +5,16 @@ import ( ) type Client struct { - accountId int64 // 账号id - licenseKey string // 许可证密钥 - asnDb *geoip2.Reader - cityDb *geoip2.Reader - countryDb *geoip2.Reader + asnDb *geoip2.Reader + cityDb *geoip2.Reader + countryDb *geoip2.Reader } -func New(licenseKey string) (*Client, error) { +func New() (*Client, error) { var err error c := &Client{} - c.licenseKey = licenseKey - c.asnDb, err = geoip2.FromBytes(asnBuff) if err != nil { return nil, err diff --git a/geoip/download_url.go b/geoip/download_url.go index f930d77..5fb70aa 100644 --- a/geoip/download_url.go +++ b/geoip/download_url.go @@ -4,44 +4,28 @@ import ( "go.dtapp.net/gostring" ) -func (c *Client) GetGeoLite2AsnDownloadUrl() string { - if c.licenseKey == "" { - return "" - } - return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=YOUR_LICENSE_KEY&suffix=tar.gz", "YOUR_LICENSE_KEY", c.licenseKey) +var licenseKey = "" // 许可证密钥 + +func GetGeoLite2AsnDownloadUrl() string { + return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=YOUR_LICENSE_KEY&suffix=tar.gz", "YOUR_LICENSE_KEY", licenseKey) } -//func (c *Client) GetGeoLite2AsnCsvDownloadUrl() string { -// if c.licenseKey == "" { -// return "" -// } -// return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&license_key=YOUR_LICENSE_KEY&suffix=zip", "YOUR_LICENSE_KEY", c.licenseKey) +//func GetGeoLite2AsnCsvDownloadUrl() string { +// return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&license_key=YOUR_LICENSE_KEY&suffix=zip", "YOUR_LICENSE_KEY", licenseKey) //} -func (c *Client) GetGeoLite2CityDownloadUrl() string { - if c.licenseKey == "" { - return "" - } - return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=YOUR_LICENSE_KEY&suffix=tar.gz", "YOUR_LICENSE_KEY", c.licenseKey) +func GetGeoLite2CityDownloadUrl() string { + return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=YOUR_LICENSE_KEY&suffix=tar.gz", "YOUR_LICENSE_KEY", licenseKey) } -//func (c *Client) GetGeoLite2CityCsvDownloadUrl() string { -// if c.licenseKey == "" { -// return "" -// } -// return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&license_key=YOUR_LICENSE_KEY&suffix=zip", "YOUR_LICENSE_KEY", c.licenseKey) +//func GetGeoLite2CityCsvDownloadUrl() string { +// return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&license_key=YOUR_LICENSE_KEY&suffix=zip", "YOUR_LICENSE_KEY", licenseKey) //} -func (c *Client) GetGeoLite2CountryDownloadUrl() string { - if c.licenseKey == "" { - return "" - } - return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=YOUR_LICENSE_KEY&suffix=tar.gz", "YOUR_LICENSE_KEY", c.licenseKey) +func GetGeoLite2CountryDownloadUrl() string { + return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=YOUR_LICENSE_KEY&suffix=tar.gz", "YOUR_LICENSE_KEY", licenseKey) } -//func (c *Client) GetGeoLite2CountryCsvDownloadUrl() string { -// if c.licenseKey == "" { -// return "" -// } -// return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=YOUR_LICENSE_KEY&suffix=zip", "YOUR_LICENSE_KEY", c.licenseKey) +//func GetGeoLite2CountryCsvDownloadUrl() string { +// return gostring.Replace("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=YOUR_LICENSE_KEY&suffix=zip", "YOUR_LICENSE_KEY", licenseKey) //} diff --git a/goip.go b/goip.go index 7e48f98..3c0faf5 100644 --- a/goip.go +++ b/goip.go @@ -20,7 +20,7 @@ type Client struct { } // NewIp 实例化 -func NewIp(geoIpLicenseKey string) *Client { +func NewIp() *Client { c := &Client{} @@ -32,7 +32,7 @@ func NewIp(geoIpLicenseKey string) *Client { c.ip2regionV2Client, _ = ip2region_v2.New() - c.geoIpClient, _ = geoip.New(geoIpLicenseKey) + c.geoIpClient, _ = geoip.New() return c }