ip2region

package module
v0.0.0-...-4659f50 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

ip2region

离线IP地址定位库

使用
package main

import (
	"fmt"

	"devgit.starschina.com/wangjiangwei/ip2region"
)

func main() {
	region, err := ip2region.New("./data/ip2region.db")
	defer region.Close()
	if err != nil {
		fmt.Println(err)
		return
	}
	ip, err := region.MemorySearch("127.0.0.1")
	fmt.Println(ip, err)
	ip, err = region.BinarySearch("127.0.0.1")
	fmt.Println(ip, err)
	ip, err = region.BtreeSearch("127.0.0.1")
	fmt.Println(ip, err)
}

Documentation

Index

Constants

View Source
const (
	INDEX_BLOCK_LENGTH  = 12
	TOTAL_HEADER_LENGTH = 8192
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Ip2Region

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

func New

func New(path string) (*Ip2Region, error)

func (*Ip2Region) BinarySearch

func (i2r *Ip2Region) BinarySearch(ipStr string) (ipInfo IpInfo, err error)

func (*Ip2Region) BtreeSearch

func (i2r *Ip2Region) BtreeSearch(ipStr string) (ipInfo IpInfo, err error)

func (*Ip2Region) Close

func (ip *Ip2Region) Close()

func (*Ip2Region) MemorySearch

func (i2r *Ip2Region) MemorySearch(ipStr string) (ipInfo IpInfo, err error)

type IpInfo

type IpInfo struct {
	CityId   int64
	Country  string
	Region   string
	Province string
	City     string
	ISP      string
	County   string
}

func (IpInfo) String

func (ip IpInfo) String() string

Jump to

Keyboard shortcuts

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