Documentation ¶
Index ¶
- Constants
- Variables
- func CutJsonp(regex, jsonp string) (string, error)
- type Engine
- func (engine *Engine) Destroy()
- func (engine *Engine) Get(key string) Finder
- func (engine *Engine) GetHowWordFinder(key string) *HotWordFinder
- func (engine *Engine) GetIP2LocFinder() *IP2LocFinder
- func (engine *Engine) GetPhoneFinder() *PhoneFinder
- func (engine *Engine) GetSuggestionFinder(key string) *SuggestionFinder
- func (engine *Engine) GetWeatherFinder(key string) *WeatherFinder
- func (engine *Engine) Register(key string, finder Finder)
- func (engine *Engine) RegisterByKind(kind, key string, finder Finder)
- func (engine *Engine) UnRegister(key string)
- type Finder
- type HotWordFinder
- type HotWordResult
- func BaiduHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)
- func SmHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)
- func SoGouHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)
- func SoHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)
- func TouTiaoHotWordFind(hwf *HotWordFinder, from string, suggestUrl string) ([]*HotWordResult, error)
- type IP2LocFinder
- type IP2LocResult
- type PhoneFinder
- type PhoneResult
- type SuggestionFinder
- type SuggestionResult
- type WeatherFinder
- type WeatherResult
Constants ¶
const ( KindIP2Loc = "ip2location" KindPhone = "phone" KindWeather = "weather" KindHotword = "hotword" KindSuggestion = "suggestion" VERSION = "v1.0.14" )
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 )
const ( CMCC byte = iota + 0x01 //中国移动 CUCC //中国联通 CTCC //中国电信 CTCC_V //中国电信虚拟运营商 CUCC_V //中国联通虚拟运营商 CMCC_V //中国移动虚拟运营商 PhoneIntLen = 4 PhoneCharLen = 1 PhoneHeadLength = 8 PhoneIndexLength = 9 )
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 )
const ( // he weather WeatherHe = "heweather" WeatherKindHeWeather = "weather" WeatherKindHeAir = "air" // sina weather WeatherSina = "sina" // config WeatherHttpTimeout = 60 )
Variables ¶
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", } )
Functions ¶
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
/////////////////////////// finder engine /////////////////////////// Engine is default finder implement.
func (*Engine) Destroy ¶
func (engine *Engine) Destroy()
Destroy will destroy all finder, so it only is called once.
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) RegisterByKind ¶ added in v1.0.7
Register set @finder with @kind @key to local memory.
func (*Engine) UnRegister ¶
UnRegister gets finder map.
type Finder ¶
type Finder interface {
Close()
}
/////////////////////////// finder interface ///////////////////////////
type HotWordFinder ¶
/////////////////////////// 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 ¶
/////////////////////////// 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
/////////////////////////// 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
/////////////////////////// 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 ¶
/////////////////////////// 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