ip4region

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: BSD-3-Clause-Clear Imports: 5 Imported by: 0

README

ip4region

介绍

ip4region 的golang module. 可以通过 import gitee.com/RickieL/ip4region 来使用

使用说明

package main

import (
    "fmt"
    "os"

    "gitee.com/RickieL/ip4region"
)

func main() {

    db := os.Args[1]

    _, err := os.Stat(db)
    if os.IsNotExist(err) {
        panic("not found db " + db)
    }

    region, err := ip4region.New(db)
    defer region.Close()

    ip, err := region.BinarySearch(os.Args[2])

    fmt.Printf("ip: %v, \nerr: %v\n", ip, err)
}
bash > go run main.go ../ip4regionMaker/ip4region.db 1.0.3.1 

ip: 中国|0|福建省|福州市|电信, 
err: <nil>

Documentation

Index

Constants

View Source
const (
	// IndexBlockLength IndexBlock长度
	IndexBlockLength int64 = 12

	// SuperBlockLength 超级块的长度
	SuperBlockLength int64 = 8

	// TotalHeaderLength TotalHeader 长度  16k,可以存储2048个index particon
	TotalHeaderLength int64 = 1024 * 16

	// DataStartPos 数据开始的位置
	DataStartPos int64 = SuperBlockLength + TotalHeaderLength
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IP4Region

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

IP4Region ip4region的结构体

func New

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

New 初始化ip4region

func (*IP4Region) BinarySearch

func (ip4 *IP4Region) BinarySearch(ipStr string) (ipInfo IPInfo, err error)

BinarySearch 使用二分法进行搜索

func (*IP4Region) BtreeSearch

func (ip4 *IP4Region) BtreeSearch(ipStr string) (ipInfo IPInfo, err error)

BtreeSearch 使用btree的方法进行搜索

func (*IP4Region) Close

func (ip4 *IP4Region) Close()

Close 关闭ip4region实例

func (*IP4Region) MemorySearch

func (ip4 *IP4Region) MemorySearch(ipStr string) (ipInfo IPInfo, err error)

MemorySearch 在内存进行搜索

type IPInfo

type IPInfo struct {
	Country  string
	Region   string
	Province string
	City     string
	ISP      string
}

IPInfo ipinfo的结构体

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