ipgeo

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: GPL-3.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// NextTraceAPIProvider is the canonical user-facing provider value for the official API.
	NextTraceAPIProvider = "NextTrace-API"

	// SourceNamespaceNextTraceAPI identifies the official NextTrace GeoIP service.
	SourceNamespaceNextTraceAPI = "nexttrace-api"
	// SourceNamespaceIPAPI identifies both IPAPI.com and ip-api.com aliases.
	SourceNamespaceIPAPI = "ip-api.com"
	// SourceNamespaceIPSB identifies the IP.SB provider.
	SourceNamespaceIPSB = "ip.sb"
	// SourceNamespaceIPInsight identifies the IPInsight provider.
	SourceNamespaceIPInsight = "ipinsight"
	// SourceNamespaceIPInfo identifies the IPInfo provider.
	SourceNamespaceIPInfo = "ipinfo"
	// SourceNamespaceIPInfoLocal identifies the local IPInfo database.
	SourceNamespaceIPInfoLocal = "ipinfolocal"
	// SourceNamespaceChunzhen identifies the local Chunzhen database.
	SourceNamespaceChunzhen = "chunzhen"
	// SourceNamespaceIPDBOne identifies the IPDB.One provider.
	SourceNamespaceIPDBOne = "ipdb.one"
	// SourceNamespaceDisableGeoIP identifies the no-op GeoIP provider.
	SourceNamespaceDisableGeoIP = "disable-geoip"
	// SourceNamespaceDN42 identifies the DN42 GeoFeed provider.
	SourceNamespaceDN42 = "dn42"

	// SourceBackendNextTraceAPIV3 identifies the WebSocket API implementation.
	SourceBackendNextTraceAPIV3 = "v3-websocket"
	// SourceBackendNextTraceAPIV4 identifies the HTTP API implementation.
	SourceBackendNextTraceAPIV4 = "v4-http"
	// SourceBackendDN42GeoFeed identifies the DN42 GeoFeed implementation.
	SourceBackendDN42GeoFeed = "geofeed"
)
View Source
const (
	NextTraceAPIV4TokenPageURL = "https://api.nxtrace.org/v4/api-tokens"
)

Variables

View Source
var IPPools = IPPool{
	// contains filtered or unexported fields
}
View Source
var LangMap = map[string]string{
	"en": "en",
	"cn": "zh",
}

LangMap shows language mapping for IPDB.One API

Functions

func CanonicalizeNextTraceAPIProvider added in v1.7.3

func CanonicalizeNextTraceAPIProvider(provider string) string

CanonicalizeNextTraceAPIProvider maps current and legacy official API names to the canonical value.

func IsNextTraceAPIProvider added in v1.7.3

func IsNextTraceAPIProvider(provider string) bool

IsNextTraceAPIProvider reports whether provider names the official API or a legacy alias.

func LtdCodeToCountryOrAreaName

func LtdCodeToCountryOrAreaName(Code string) string

func NextTraceAPIV4TokenConfigured added in v1.7.0

func NextTraceAPIV4TokenConfigured() bool

func PrepareNextTraceAPIV4FastIP added in v1.7.0

func PrepareNextTraceAPIV4FastIP(ctx context.Context, enableOutput bool) error

Types

type IPDBOneClient added in v1.4.1

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

IPDBOneClient handles communication with IPDB.One API

func NewIPDBOneClient added in v1.4.1

func NewIPDBOneClient() *IPDBOneClient

NewIPDBOneClient creates a new client for IPDB.One with default configuration

func (*IPDBOneClient) LookupIP added in v1.4.1

func (c *IPDBOneClient) LookupIP(ip string, lang string) (*IPGeoData, error)

LookupIP queries the IP information from IPDB.One

type IPDBOneConfig added in v1.4.1

type IPDBOneConfig struct {
	BaseURL string
	ApiID   string
	ApiKey  string
}

IPDBOneConfig holds the configuration for IPDB.One service

func GetDefaultConfig added in v1.4.1

func GetDefaultConfig() *IPDBOneConfig

GetDefaultConfig returns the default configuration with fallback values

type IPDBOneTokenCache added in v1.4.1

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

IPDBOneTokenCache manages the caching of auth tokens

func (*IPDBOneTokenCache) GetToken added in v1.4.1

func (c *IPDBOneTokenCache) GetToken() string

GetToken retrieves cached token if valid, otherwise returns empty string

func (*IPDBOneTokenCache) SetToken added in v1.4.1

func (c *IPDBOneTokenCache) SetToken(token string, expiresIn time.Duration)

SetToken updates the token with its expiration time

type IPGeoData

type IPGeoData struct {
	IP        string              `json:"ip"`
	Asnumber  string              `json:"asnumber"`
	Country   string              `json:"country"`
	CountryEn string              `json:"country_en"`
	Prov      string              `json:"prov"`
	ProvEn    string              `json:"prov_en"`
	City      string              `json:"city"`
	CityEn    string              `json:"city_en"`
	District  string              `json:"district"`
	Owner     string              `json:"owner"`
	Isp       string              `json:"isp"`
	Domain    string              `json:"domain"`
	Whois     string              `json:"whois"`
	Lat       float64             `json:"lat"`
	Lng       float64             `json:"lng"`
	Prefix    string              `json:"prefix"`
	Router    map[string][]string `json:"router"`
	Source    string              `json:"source"`
}

func Chunzhen

func Chunzhen(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData, error)

func DN42

func DN42(ip string, _ time.Duration, _ string, _ bool) (*IPGeoData, error)

func Filter

func Filter(ip string) (*IPGeoData, bool)

Filter 被选到的返回 geodata, true 否则返回 nil, false

func IPApiCom

func IPApiCom(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData, error)

func IPDBOne added in v1.4.1

func IPDBOne(ip string, timeout time.Duration, lang string, _ bool) (*IPGeoData, error)

IPDBOne looks up IP information from IPDB.One (maintains backward compatibility)

func IPInSight

func IPInSight(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData, error)

func IPInfo

func IPInfo(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData, error)

func IPInfoLocal

func IPInfoLocal(ip string, _ time.Duration, _ string, _ bool) (*IPGeoData, error)

func IPSB

func IPSB(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData, error)

func LeoIP

func LeoIP(ip string, timeout time.Duration, lang string, maptrace bool) (*IPGeoData, error)

LeoIP is kept for source compatibility. Deprecated: use NextTraceAPIV3GeoIP.

func LeoIPNextTraceAPIV4HTTP added in v1.7.0

func LeoIPNextTraceAPIV4HTTP(ip string, timeout time.Duration, lang string, maptrace bool) (*IPGeoData, error)

LeoIPNextTraceAPIV4HTTP is kept for source compatibility. Deprecated: use NextTraceAPIV4GeoIP.

func NextTraceAPIV3GeoIP added in v1.7.3

func NextTraceAPIV3GeoIP(ip string, timeout time.Duration, lang string, maptrace bool) (*IPGeoData, error)

NextTraceAPIV3GeoIP queries the NextTrace API v3 WebSocket service.

func NextTraceAPIV4GeoIP added in v1.7.3

func NextTraceAPIV4GeoIP(ip string, timeout time.Duration, lang string, maptrace bool) (*IPGeoData, error)

NextTraceAPIV4GeoIP queries the NextTrace API v4 HTTP service.

type IPPool

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

IPPool IP 查询池 map - ip - ip channel

type NextTraceAPIV4Client added in v1.7.0

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

func NewNextTraceAPIV4Client added in v1.7.0

func NewNextTraceAPIV4Client(endpoint string, token string, httpClient *http.Client) *NextTraceAPIV4Client

func (*NextTraceAPIV4Client) Lookup added in v1.7.0

type NextTraceAPIV4Quota added in v1.7.0

type NextTraceAPIV4Quota struct {
	Remaining    uint64
	HasRemaining bool
	ExpiresAt    time.Time
	HasExpiresAt bool
	Cost         uint64
	HasCost      bool
	Source       string
}

type Source

type Source = func(ip string, timeout time.Duration, lang string, maptrace bool) (*IPGeoData, error)

func GetSource

func GetSource(s string) Source

func GetSourceWithGeoDNS added in v1.5.2

func GetSourceWithGeoDNS(s string, dotServer string) Source

func LeoMoeAPISource added in v1.7.0

func LeoMoeAPISource() Source

LeoMoeAPISource is kept for source compatibility. Deprecated: use NextTraceAPISource.

func NextTraceAPISource added in v1.7.3

func NextTraceAPISource() Source

NextTraceAPISource selects v4 when a token is configured and otherwise uses v3.

type SourceDescriptor added in v1.7.4

type SourceDescriptor struct {
	Source        Source
	Namespace     string
	Backend       string
	Generation    uint64
	HasGeneration bool
	// GeoDNSResolver identifies an explicitly wrapped resolver scope, including
	// the empty system resolver. It separates in-flight work, not cached values.
	GeoDNSResolver    string
	HasGeoDNSResolver bool
}

SourceDescriptor identifies a Source and the backend state that affects its results. Namespace is empty only for descriptors constructed by callers.

func GetSourceDescriptor added in v1.7.4

func GetSourceDescriptor(s string) SourceDescriptor

GetSourceDescriptor returns the current descriptor for provider s.

func GetSourceDescriptorWithGeoDNS added in v1.7.4

func GetSourceDescriptorWithGeoDNS(s string, dotServer string) SourceDescriptor

GetSourceDescriptorWithGeoDNS returns the current descriptor with a scoped DNS policy applied to its Source.

type SourceDescriptorSession added in v1.7.4

type SourceDescriptorSession struct {
	Current func() SourceDescriptor
	Refresh func()
}

SourceDescriptorSession returns a descriptor whose Source and generation belong to the same provider snapshot. Refresh is nil for static providers.

func GetSourceDescriptorSession added in v1.7.4

func GetSourceDescriptorSession(s string) SourceDescriptorSession

GetSourceDescriptorSession returns a provider session with canonical cache identity metadata.

func GetSourceDescriptorSessionWithGeoDNS added in v1.7.4

func GetSourceDescriptorSessionWithGeoDNS(s string, dotServer string) SourceDescriptorSession

GetSourceDescriptorSessionWithGeoDNS applies a scoped DNS policy without changing descriptor identity or refresh behavior.

type SourceSession added in v1.7.4

type SourceSession struct {
	Source  Source
	Refresh func()
}

SourceSession pins any provider state used by Source. Refresh is non-nil only for providers whose snapshot can change during a long-lived session.

func GetSourceSession added in v1.7.4

func GetSourceSession(s string) SourceSession

GetSourceSession returns a source whose provider state is fixed until Refresh is called.

func GetSourceSessionWithGeoDNS added in v1.7.4

func GetSourceSessionWithGeoDNS(s string, dotServer string) SourceSession

GetSourceSessionWithGeoDNS applies a scoped DNS policy without changing the session's refresh behavior.

Jump to

Keyboard shortcuts

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