geoIp

package
v1.1.49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GeoIpDBCurVersion string

GeoIpDBCurVersion 当前 Country 库版本号(用于页面展示)

Functions

func FindFromIPAPI added in v1.1.12

func FindFromIPAPI(ip string) (countryCode string, err error)

FindFromIPAPI 通过 ip-api.com 查询国家码(带缓存,原实现无超时无缓存)

func GetASN added in v1.1.0

func GetASN(ipStr string) (string, error)

GetASN 返回 IP 的 ASN 组织名

func InitGeoIpASNDB added in v1.1.0

func InitGeoIpASNDB()

InitGeoIpASNDB 初始化 ASN 库:本地已有则直接加载(原实现每次启动全量下载)

func InitGeoIpDB

func InitGeoIpDB() error

InitGeoIpDB 初始化数据库: 1. 本地已有 Country.mmdb 则直接加载(秒开),否则下载并落盘 2. 加载 emoji 映射 3. 初始化 ASN 库

func IsCDN added in v1.1.0

func IsCDN(ipStr string) bool

IsCDN 基于本地 ASN 库判断 IP 是否属于 CDN

func UpdateGeoIP added in v0.9.0

func UpdateGeoIP()

UpdateGeoIP 检查远程版本,有更新则下载替换(由 cron 每日调用)。 修复原实现:本地文件加载模式版本号为空导致永远跳过更新检查。

func UpdateGeoIpASNDB added in v1.1.0

func UpdateGeoIpASNDB()

UpdateGeoIpASNDB 下载 ASN 库并原子替换(由 cron 每日调用)

Types

type CountryEmoji

type CountryEmoji struct {
	Code  string `json:"code"`
	Emoji string `json:"emoji"`
}

CountryEmoji flags.json 中的国家与 emoji 映射项

type GeoIP

type GeoIP struct {
	// contains filtered or unexported fields
}

GeoIP 地理位置查询器(保持对外 API 不变)

var GeoIpDB GeoIP

GeoIpDB 全局地理位置查询器

func (GeoIP) Find

func (g GeoIP) Find(ipORdomain string) (ip, country string, err error)

Find ip info:入参为 IP 时直接解析,避免不必要的 DNS 查询

func (GeoIP) FindCountryIsoEmoji added in v1.0.5

func (g GeoIP) FindCountryIsoEmoji(countryIsoCode string) string

type IPAPIResponse added in v1.1.12

type IPAPIResponse struct {
	CountryCode string `json:"countryCode"`
	Status      string `json:"status"`
	Message     string `json:"message"`
}

IPAPIResponse ip-api.com 查询响应

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL