ip17mon

package module
v0.0.0-...-28e84cd Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2016 License: MIT Imports: 5 Imported by: 0

README

17mon IP location data for Golang

Circle CI

特性

  • 高效的查找算法,查询性能100w/s
  • 支持build出的bin文件包含原始数据

安装

go get -u github.com/wangtuanjie/ip17mon

使用

import (
	"fmt"
	"github.com/wangtuanjie/ip17mon"
)

func init() {
	if err := ip17mon.Init("your data file"); err != nil {
		panic(err)
	}
}

func main() {
	loc, err := ip17mon.Find("116.228.111.18")
	if err != nil {
		fmt.Println("err:", err)
		return
	}
	fmt.Println(loc)
}

更多请参考example

许可证

基于 MIT 协议发布

Documentation

Index

Constants

View Source
const Null = "N/A"

Variables

View Source
var (
	ErrInvalidIp = errors.New("invalid ip format")
)

Functions

func Init

func Init(dataFile string) (err error)

Init defaut locator with dataFile

func InitWithData

func InitWithData(data []byte)

Init defaut locator with data

Types

type LocationInfo

type LocationInfo struct {
	Country string `json:"country"`
	Region  string `json:"region"`
	City    string `json:"city"`
	Isp     string `json:"isp"`
	Ip      string `json:"ip"`
}

func Find

func Find(ipstr string) (*LocationInfo, error)

Find locationInfo by ip string It will return err when ipstr is not a valid format

func FindByUint

func FindByUint(ip uint32) *LocationInfo

Find locationInfo by uint32

type Locator

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

func NewLocator

func NewLocator(dataFile string) (loc *Locator, err error)

New locator with dataFile

func NewLocatorWithData

func NewLocatorWithData(data []byte) (loc *Locator)

New locator with data

func (*Locator) Find

func (loc *Locator) Find(ipstr string) (info *LocationInfo, err error)

Find locationInfo by ip string It will return err when ipstr is not a valid format

func (*Locator) FindByUint

func (loc *Locator) FindByUint(ip uint32) (info *LocationInfo)

Find locationInfo by uint32

Directories

Path Synopsis
example
qip

Jump to

Keyboard shortcuts

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