phonedata

package module
v0.0.0-...-f493732 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

phonedata

note: data from network, please use after identification.

Build Status Code maintainability code coverage Windows Build Status Author GoDoc Report

install

go get -u github.com/dingdayu/phonedata

example

package main

import (
	"fmt"
	"github.com/dingdayu/phonedata"
)

func main() {
	info, _ := phonedata.Find("13298181006")
	fmt.Println(info)
}

at go 1.12, go models

file: example/main.go

benchmark

go test -v -bench=".*" -benchmem -memprofile memprofile.out -cpuprofile cpuprofile.out
=== RUN   TestIsPhone
--- PASS: TestIsPhone (0.00s)
=== RUN   TestTotalRecord
--- PASS: TestTotalRecord (0.00s)
=== RUN   TestVersion
--- PASS: TestVersion (0.00s)
=== RUN   TestLoadDataFile
--- PASS: TestLoadDataFile (0.00s)
=== RUN   Example
--- PASS: Example (0.00s)
goos: darwin
goarch: amd64
pkg: phonedata
BenchmarkIsPhone-4        200000             13505 ns/op            9209 B/op        114 allocs/op
BenchmarkVersion-4      300000000                5.21 ns/op            0 B/op          0 allocs/op
BenchmarkFind-4          3000000               449 ns/op             224 B/op          6 allocs/op
PASS
ok      phonedata       6.922s

at: MacBook Pro(Intel Core i7/3.1 GHz)

Reference

The project is affected by the following projects or articles.

Documentation

Overview

Package phonedata 内地手机号归属信息. data file from: https://github.com/ls0f/phone data file format:

| 4 bytes |                  <- phone.dat 版本号
------------
| 4 bytes |                  <-  第一个索引的偏移
-----------------------
|  offset - 8         |      <-  记录区
-----------------------
|  index              |      <-  索引区
-----------------------
Example

查询一个手机号的归属地信息

package main

import (
	"fmt"
	"github.com/dingdayu/phonedata"
)

func main() {
	info, _ := phonedata.Find("13298181000")
	fmt.Println(info)
}
Output:
PhoneNum: 13298181000
AreaZone: 0371
CardType: 中国联通
City: 郑州
ZipCode: 450000
Province: 河南

Index

Examples

Constants

View Source
const (
	// 归属地标识符
	CMCC             byte = iota + 0x01 // 中国移动
	CUCC                                // 中国联通
	CTCC                                // 中国电信
	CTCCV                               // 电信虚拟运营商
	CUCCV                               // 联通虚拟运营商
	CMCCV                               // 移动虚拟运营商
	IntLen           = 4
	CharLen          = 1
	HeadLength       = 8
	PhoneIndexLength = 9
	DataFile         = "data/phone.dat"
)

Variables

View Source
var (

	// CardType 运营商类型
	CardType = map[byte]string{
		CMCC:  "中国移动",
		CUCC:  "中国联通",
		CTCC:  "中国电信",
		CTCCV: "中国电信虚拟运营商",
		CUCCV: "中国联通虚拟运营商",
		CMCCV: "中国移动虚拟运营商",
	}
)

Functions

func IsPhone

func IsPhone(v string) bool

IsPhone 检查一个字符串是否合法

func LoadDataFile

func LoadDataFile(file string) (err error)

LoadDataFile 加载自定义 data 文件

func TotalRecord

func TotalRecord() int32

TotalRecord 获取 data 文件的记录数量

func Version

func Version() string

Version 获取 data 文件头部版本号

Types

type PhoneRecord

type PhoneRecord struct {
	PhoneNum string
	Province string
	City     string
	ZipCode  string
	AreaZone string
	CardType string
}

PhoneRecord 手机归属地信息

func Find

func Find(phoneNum string) (pr *PhoneRecord, err error)

Find 获取一个手机号的归属地信息

func (PhoneRecord) String

func (pr PhoneRecord) String() string

PhoneRecord 格式化输出归属地信息

Directories

Path Synopsis
Package data Code generated by go-bindata.
Package data Code generated by go-bindata.

Jump to

Keyboard shortcuts

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