ip2region

package
v2.0.26 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 4 Imported by: 1

README

IP地址位置查询服务

➜  golang git:(v2.0_xdb) ✗ ./xdb_searcher search --db=../../data/ip2region.xdb
ip2region xdb searcher test program, type `quit` to exit
ip2region>> 1.2.3.4
{region:美国|0|华盛顿|0|谷歌, took:101.57µs}

关于Ip数据库文件请从 ip2region下载: data/ip2region.xdb

Documentation

Index

Constants

View Source
const (
	AppName = "ip2region"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IPInfo

type IPInfo struct {
	Country  string `bson:"country" json:"country"`
	Region   string `bson:"region" json:"region"`
	Province string `bson:"province" json:"province"`
	City     string `bson:"city" json:"city"`
	ISP      string `bson:"isp" json:"isp"`
}

IPInfo todo

func NewDefaultIPInfo

func NewDefaultIPInfo() *IPInfo

NewDefaultIPInfo todo

func ParseIpInfoFromString

func ParseIpInfoFromString(raw string) (*IPInfo, error)

中国|0|四川省|成都市|电信

func (*IPInfo) IsPublic

func (ip *IPInfo) IsPublic() bool

func (IPInfo) String

func (ip IPInfo) String() string

type Ip2Region

type Ip2Region struct {
	ioc.ObjectImpl

	// 功能开关, 开启后 需要读取DB文件, 在执行单元测试时很不方便
	Enable bool `json:"enable" yaml:"enable" toml:"enable" env:"ENABLE"`
	// DB 文件路径
	DBPath string `json:"db_path" yaml:"db_path" toml:"db_path" env:"DB_PATH"`
	// contains filtered or unexported fields
}

func (*Ip2Region) Init

func (i *Ip2Region) Init() error

func (*Ip2Region) LookupIP

func (i *Ip2Region) LookupIP(ip string) (*IPInfo, error)

func (*Ip2Region) Name

func (i *Ip2Region) Name() string

type IpRegionSearcher

type IpRegionSearcher interface {
	LookupIP(ip string) (*IPInfo, error)
}

func Get

func Get() IpRegionSearcher

Jump to

Keyboard shortcuts

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