finder

package module
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Finder (GEO, China Phone, Weather)

快速使用

package main

import (
	"log"

	fd "github.com/20326/finder"
)

func main() {
	// new engine
	engine := fd.NewEngine()

	// register
	engine.Register(fd.KindPhone, fd.NewPhoneFinder("../phone.2004.dat"))

	pf := engine.GetPhoneFinder()
	phoneResult, err := pf.Find("18600228899")
	log.Printf("Phone: %v err: %v", phoneResult, err)

	// unregister
	engine.UnRegister(fd.KindPhone)

	// destroy
	engine.Destroy()
}

性能测试

go test -v --bench="."

手机号归属地查询

最新最全的中国境内手机号归属地信息库查询工具

手机号归属地数据打包工具

手机号归属地数据格式

    | 4 bytes |                     <- phone.dat 版本号(如:1701即17年1月份)
    ------------
    | 4 bytes |                     <-  第一个索引的偏移
    -----------------------
    |  offset - 8            |      <-  记录区
    -----------------------
    |  index                 |      <-  索引区
    -----------------------
  1. 头部为8个字节,版本号为4个字节,第一个索引的偏移为4个字节;
  2. 记录区 中每条记录的格式为"<省份>|<城市>|<邮编>|<长途区号>\0"。 每条记录以'\0'结束;
  3. 索引区 中每条记录的格式为"<手机号前七位><记录区的偏移><卡类型>",每个索引的长度为9个字节;

手机号归属地数据更新(phone.2004.dat)

  • 归属地信息库文件大小:4,040,893 字节
  • 归属地信息库最后更新:2020年04月
  • 手机号段记录条数:447893

GEO数据库 ip2region.db

https://github.com/lionsoul2014/ip2region/raw/master/data/ip2region.db

License

Copyright (c) 2020 (brian)

Licensed under the MIT license (LICENSE).

Documentation

Index

Constants

View Source
const (
	KindIP2Loc     = "ip2location"
	KindPhone      = "phone"
	KindWeather    = "weather"
	KindHotword    = "hotword"
	KindSuggestion = "suggestion"

	VERSION = "v1.0.14"
)
View Source
const (
	// HotWord  kind
	HotWordBaidu   = "baidu"
	HotWordTouTiao = "toutiao"
	HotWord360So   = "so"
	HotWordSogou   = "sogou"
	HotWordSm      = "sm"

	// Url
	BaiduHotWordsUrl   = "https://top.baidu.com/api/board?platform=wise&tab=realtime&tag=%7B%7D"
	SoHotWordsUrl      = "https://m.so.com/home/data?types=Hotwords&fmt=json"
	SoGouHotWordsUrl   = "https://wap.sogou.com/data/hotwords/sogou_app.js"
	TouTiaoHotWordsUrl = "https://i.snssdk.com/hot-event/hot-board/?count=50&tab_name=stream&origin=hot_board"
	SmHotWordsUrl      = "http://api.m.sm.cn/rest?method=tools.hot&size=0"

	// Suggest Url
	DefaultBaiduSuggestUrlFmt   = "http://m.baidu.com/from=${from}/s?word=${keyword}&bd_page_type=1"
	DefaultSoGouSuggestUrlFmt   = "https://wap.sogou.com/web/searchList.jsp?keyword=${keyword}&e=${from}"
	Default360SoSuggestUrlFmt   = "https://m.so.com/s?q=${keyword}&src=${from}"
	DefaultTouTiaoSuggestUrlFmt = "https://so.toutiao.com/search?keyword=${keyword}&traffic_source=${from}&original_source=1&source=client"
	DefaultSmSuggestUrlFmt      = "http://m.yz2.sm.cn/s?q=${keyword}&by=hot&from=${from}"

	// Config
	HotWordHttpTimeout = 60
)
View Source
const (
	CMCC             byte = iota + 0x01 //中国移动
	CUCC                                //中国联通
	CTCC                                //中国电信
	CTCC_V                              //中国电信虚拟运营商
	CUCC_V                              //中国联通虚拟运营商
	CMCC_V                              //中国移动虚拟运营商
	PhoneIntLen      = 4
	PhoneCharLen     = 1
	PhoneHeadLength  = 8
	PhoneIndexLength = 9
)
View Source
const (
	// Suggestion  kind
	SuggestionBaidu = "baidu"

	// Url
	BaiduSuggestionUrl = "https://m.baidu.com/su?type=3&ie=utf-8&json=1&wd=${keyword}"

	// Suggest Url
	DefaultBaiduSuggestionUrlFmt = "http://m.baidu.com/from=${from}/s?word=${keyword}&bd_page_type=1"

	// Config
	SuggestionHttpTimeout = 60
)
View Source
const (
	// he weather
	WeatherHe            = "heweather"
	WeatherKindHeWeather = "weather"
	WeatherKindHeAir     = "air"

	// sina weather
	WeatherSina = "sina"

	// config
	WeatherHttpTimeout = 60
)

Variables

View Source
var (
	CityCodeMap = map[string]string{}/* 307 elements not displayed */

	CityPinYinMap = map[string]string{}/* 341 elements not displayed */

	CityName2PinYinMap = map[string]string{}/* 307 elements not displayed */

	HeWeatherImgMap = map[string]string{
		"100": "w_01_01_00",
		"101": "w_02_08_00",
		"102": "w_01_16_00",
		"103": "w_02_08_00",
		"104": "w_07_25_00",
		"200": "w_01_09_00",
		"201": "w_05_13_00",
		"202": "w_01_09_00",
		"203": "w_01_09_00",
		"204": "w_01_09_00",
		"205": "w_01_09_00",
		"206": "w_01_09_00",
		"207": "w_01_09_00",
		"208": "w_01_09_00",
		"209": "w_01_09_00",
		"210": "w_01_09_00",
		"211": "w_01_09_00",
		"212": "w_01_09_00",
		"213": "w_01_09_00",
		"300": "w_03_28_00",
		"301": "w_08_11_00",
		"302": "w_08_11_00",
		"303": "w_08_11_00",
		"304": "w_03_26_00",
		"305": "w_03_22_00",
		"306": "w_03_03_00",
		"307": "w_03_03_00",
		"308": "w_03_03_00",
		"309": "w_03_22_00",
		"310": "w_03_03_00",
		"311": "w_03_03_00",
		"312": "w_03_03_00",
		"313": "w_04_27_00",
		"314": "w_03_30_00",
		"315": "w_03_03_00",
		"316": "w_03_03_00",
		"317": "w_03_03_00",
		"318": "w_03_03_00",
		"399": "w_03_22_00",
		"400": "w_04_21_00",
		"401": "w_04_05_00",
		"402": "w_04_02_00",
		"403": "w_04_02_00",
		"404": "w_04_27_00",
		"405": "w_04_27_00",
		"406": "w_04_27_00",
		"407": "w_04_21_00",
		"408": "w_04_29_00",
		"409": "w_04_05_00",
		"410": "w_04_02_00",
		"499": "w_04_29_00",
		"500": "w_05_20_00",
		"501": "w_05_20_00",
		"502": "w_06_12_00",
		"503": "w_09_24_00",
		"504": "w_09_10_00",
		"507": "w_09_24_00",
		"508": "w_09_15_00",
		"509": "w_05_20_00",
		"510": "w_05_20_00",
		"511": "w_06_12_00",
		"512": "w_06_12_00",
		"513": "w_06_12_00",
		"514": "w_05_20_00",
		"515": "w_05_20_00",
		"900": "w_01_01_00",
		"901": "w_01_17_00",
		"999": "w_01_18_00",
	}

	SinaWeatherImgMap = map[string]string{
		"w_03_06_00": "w_03_03_00",
		"w_03_19_00": "w_03_03_00",
		"w_04_27_01": "w_04_27_00",
		"w_04_27_00": "w_04_27_00",
		"w_09_10_00": "w_09_10_00",
		"w_09_10_01": "w_09_10_00",
		"w_03_26_01": "w_03_26_00",
		"w_04_02_01": "w_04_02_00",
		"w_04_02_00": "w_04_02_00",
		"w_03_26_00": "w_03_26_00",
		"w_06_12_01": "w_06_12_00",
		"w_06_12_00": "w_06_12_00",
		"w_02_08_00": "w_02_08_00",
		"w_09_24_00": "w_09_24_00",
		"w_08_04_01": "w_03_26_00",
		"w_04_05_01": "w_04_05_00",
		"w_04_05_00": "w_04_05_00",
		"w_05_31_01": "w_05_20_00",
		"w_05_31_00": "w_05_20_00",
		"w_03_28_01": "w_03_28_00",
		"w_03_28_00": "w_03_28_00",
		"w_01_09_00": "w_01_09_00",
		"w_01_09_01": "w_01_09_00",
		"w_03_22_01": "w_03_22_00",
		"w_03_22_00": "w_03_22_00",
		"w_01_01_01": "w_01_01_01",
		"w_08_11_00": "w_08_11_00",
		"w_08_11_01": "w_08_11_00",
		"w_01_18_00": "w_01_18_00",
		"w_01_18_01": "w_01_18_00",
		"w_09_24_01": "w_09_24_00",
		"w_04_29_01": "w_04_29_00",
		"w_04_29_00": "w_04_29_00",
		"w_01_01_00": "w_01_01_00",
		"w_03_07_00": "w_04_27_00",
		"w_04_21_01": "w_04_21_00",
		"w_03_07_01": "w_04_27_00",
		"w_03_03_00": "w_03_03_00",
		"w_05_23_00": "w_05_23_00",
		"w_03_30_00": "w_03_30_00",
		"w_03_30_01": "w_03_30_00",
		"w_03_19_01": "w_03_03_00",
		"w_05_23_01": "w_05_23_00",
		"w_02_08_01": "w_02_08_00",
		"w_08_04_00": "w_03_26_00",
		"w_04_21_00": "w_04_21_00",
		"w_05_13_01": "w_05_20_00",
		"w_05_13_00": "w_05_20_00",
		"w_01_16_00": "w_01_16_00",
		"w_01_16_01": "w_01_16_00",
		"w_03_03_01": "w_03_03_00",
		"w_05_20_01": "w_05_20_00",
		"w_05_20_00": "w_05_20_00",
		"w_01_17_01": "w_01_17_00",
		"w_01_17_00": "w_01_17_00",
		"w_09_14_00": "w_09_15_00",
		"w_09_14_01": "w_09_15_00",
		"w_07_25_00": "w_07_25_00",
		"w_07_25_01": "w_07_25_00",
		"w_09_15_01": "w_09_24_00",
		"w_09_15_00": "w_09_24_00",
		"w_03_06_01": "w_03_03_00",
	}
)
View Source
var (
	CarrierMap = map[byte]string{
		CMCC:   "中国移动",
		CUCC:   "中国联通",
		CTCC:   "中国电信",
		CTCC_V: "中国电信虚拟运营商",
		CUCC_V: "中国联通虚拟运营商",
		CMCC_V: "中国移动虚拟运营商",
	}
)

Functions

func CutJsonp added in v1.0.4

func CutJsonp(regex, jsonp string) (string, error)

Types

type Engine

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

/////////////////////////// finder engine /////////////////////////// Engine is default finder implement.

func NewEngine

func NewEngine() Engine

NewEngine creates a new Engine

func (*Engine) Destroy

func (engine *Engine) Destroy()

Destroy will destroy all finder, so it only is called once.

func (*Engine) Get

func (engine *Engine) Get(key string) Finder

Get with @key return @finder.

func (*Engine) GetHowWordFinder

func (engine *Engine) GetHowWordFinder(key string) *HotWordFinder

GetHowWordFinder with @key return @finder.

func (*Engine) GetIP2LocFinder

func (engine *Engine) GetIP2LocFinder() *IP2LocFinder

GetIP2LocFinder with @key return @finder.

func (*Engine) GetPhoneFinder

func (engine *Engine) GetPhoneFinder() *PhoneFinder

GetPhoneFinder with @key return @finder.

func (*Engine) GetSuggestionFinder added in v1.0.4

func (engine *Engine) GetSuggestionFinder(key string) *SuggestionFinder

GetSuggestionFinder with @key return @finder.

func (*Engine) GetWeatherFinder

func (engine *Engine) GetWeatherFinder(key string) *WeatherFinder

GetWeatherFinder with @key return @finder.

func (*Engine) Register

func (engine *Engine) Register(key string, finder Finder)

Register set @finder with @key to local memory.

func (*Engine) RegisterByKind added in v1.0.7

func (engine *Engine) RegisterByKind(kind, key string, finder Finder)

Register set @finder with @kind @key to local memory.

func (*Engine) UnRegister

func (engine *Engine) UnRegister(key string)

UnRegister gets finder map.

type Finder

type Finder interface {
	Close()
}

/////////////////////////// finder interface ///////////////////////////

type HotWordFinder

type HotWordFinder struct {
	Provider   string
	From       string
	TTL        int
	SuggestUrl string
}

/////////////////////////// HotWord Finder ///////////////////////////

func NewHotWordFinder

func NewHotWordFinder(provider string, from string, suggestUrl string, ttl int) *HotWordFinder

func (*HotWordFinder) Close

func (hwf *HotWordFinder) Close()

func (*HotWordFinder) Find

func (hwf *HotWordFinder) Find(from string, suggestUrl string) ([]*HotWordResult, error)

func (*HotWordFinder) GetSuggestUrl

func (hwf *HotWordFinder) GetSuggestUrl(keyword string, from string, suggestUrl string) string

func (*HotWordFinder) Version

func (hwf *HotWordFinder) Version() string

type HotWordResult

type HotWordResult struct {
	Keyword    string
	Weight     int
	SuggestUrl string
}

/////////////////////////// HotWord Result ///////////////////////////

func BaiduHotWordFind

func BaiduHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)

func SmHotWordFind added in v1.0.11

func SmHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)

func SoGouHotWordFind

func SoGouHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)

func SoHotWordFind

func SoHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)

func TouTiaoHotWordFind

func TouTiaoHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)

func (*HotWordResult) Json

func (wr *HotWordResult) Json() string

type IP2LocFinder

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

/////////////////////////// IP2Location Finder ///////////////////////////

func NewIP2LocFinder

func NewIP2LocFinder(db string) *IP2LocFinder

func (*IP2LocFinder) Close

func (iplf *IP2LocFinder) Close()

func (*IP2LocFinder) Find

func (iplf *IP2LocFinder) Find(ip string, algorithm string) (*IP2LocResult, error)

func (*IP2LocFinder) Version

func (iplf *IP2LocFinder) Version() string

type IP2LocResult

type IP2LocResult struct {
	IP       string `json:"ip"`
	CityId   int64  `json:"city_id"`
	Country  string `json:"country"`
	Region   string `json:"region"`
	Province string `json:"province"`
	City     string `json:"city"`
	ISP      string `json:"isp"`
}

/////////////////////////// IP2Location Finder Result ///////////////////////////

type PhoneFinder

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

func NewPhoneFinder

func NewPhoneFinder(db string) *PhoneFinder

func (*PhoneFinder) BtreeSearch

func (pf *PhoneFinder) BtreeSearch(phoneNum string) (*PhoneResult, error)

/////////////////////////// 二分法查询phone数据 ///////////////////////////

func (*PhoneFinder) Close

func (pf *PhoneFinder) Close()

func (*PhoneFinder) Find

func (pf *PhoneFinder) Find(key string) (*PhoneResult, error)

func (*PhoneFinder) Version

func (pf *PhoneFinder) Version() string

type PhoneResult

type PhoneResult struct {
	Phone    string `json:"phone"`
	Province string `json:"province"`
	City     string `json:"city"`
	ZipCode  string `json:"zipcode"`
	Region   string `json:"region"`
	Carrier  string `json:"carrier"`
}

/////////////////////////// Phone Finder Result ///////////////////////////

type SuggestionFinder added in v1.0.4

type SuggestionFinder struct {
	Provider   string
	From       string
	TTL        int
	SuggestUrl string
}

/////////////////////////// Suggestion Finder ///////////////////////////

func NewSuggestionFinder added in v1.0.4

func NewSuggestionFinder(provider string, from string, suggestUrl string, ttl int) *SuggestionFinder

func (*SuggestionFinder) Close added in v1.0.4

func (suf *SuggestionFinder) Close()

func (*SuggestionFinder) Find added in v1.0.4

func (suf *SuggestionFinder) Find(keyword string, from string, suggestUrl string) ([]*SuggestionResult, error)

func (*SuggestionFinder) GetSuggestUrl added in v1.0.4

func (suf *SuggestionFinder) GetSuggestUrl(keyword string, from string, suggestUrl string) string

func (*SuggestionFinder) Version added in v1.0.4

func (suf *SuggestionFinder) Version() string

type SuggestionResult added in v1.0.4

type SuggestionResult struct {
	Keyword    string
	Weight     int
	SuggestUrl string
	Query      string
}

/////////////////////////// Suggestion Result ///////////////////////////

func BaiduSuggestionFind added in v1.0.4

func BaiduSuggestionFind(suf *SuggestionFinder, keyword string, from string, suggestUrl string) ([]*SuggestionResult, error)

func (*SuggestionResult) Json added in v1.0.4

func (wr *SuggestionResult) Json() string

type WeatherFinder

type WeatherFinder struct {
	Provider string
	AppKey   string
	TTL      int
}

/////////////////////////// Weather Finder ///////////////////////////

func NewWeatherFinder

func NewWeatherFinder(provider string, appKey string, ttl int) *WeatherFinder

func (*WeatherFinder) Close

func (wf *WeatherFinder) Close()

func (*WeatherFinder) Find

func (wf *WeatherFinder) Find(city string, kind string) (*WeatherResult, error)

func (*WeatherFinder) Version

func (wf *WeatherFinder) Version() string

type WeatherResult

type WeatherResult map[string]interface{}

/////////////////////////// Weather Finder Result ///////////////////////////

func HeWeatherFind

func HeWeatherFind(wf *WeatherFinder, city string, kind string) (*WeatherResult, error)

func (*WeatherResult) Json

func (wr *WeatherResult) Json() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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