Documentation
¶
Overview ¶
Package linetype provides Phone Line Type Intelligence for North American and Mexican phone numbers.
Use Line Type Intelligence to identify the carrier and phone line type — mobile, landline, fixed VoIP, non-fixed VoIP, toll free, and more — with no per-lookup API cost. Data is loaded at runtime from a Protocol Buffers file built from published numbering-plan allocation data (NANPA, CNAC, IFT).
Quick start ¶
linetype.SetDataPath("data/phone_data.pb") // optional; auto-resolved
n := linetype.Describe("+18168037763")
fmt.Println(n.Class) // wireless
fmt.Println(n.SMSReachable) // true
fmt.Println(n.Carrier.Label()) // T-Mobile
fmt.Println(n.Region.Name) // Missouri
Direct lookups ¶
cls := linetype.Lookup("+14155551234") // class only
cr := linetype.LookupCarrier("+14155551234") // carrier info
rg := linetype.LookupRegion("+14155551234") // geographic region
Supported countries ¶
- +1 United States and Canada (NANPA block-level, O(1) array lookup)
- +52 Mexico (IFT range table, O(log n) binary search)
Scope limit ¶
This package reflects block assignment, not current line type. It does not account for local number portability. See ACCURACY.md for error analysis.
Package linetype provides Line Type Intelligence for North American (+1) and Mexican (+52) phone numbers.
Use Line Type Intelligence to identify the carrier and phone line type, such as mobile, landline, fixed VoIP, non-fixed VoIP, toll free, and more — with no per-lookup API cost.
Data is loaded at runtime from a Protocol Buffers file built from published numbering-plan allocation data (NANPA, CNAC, IFT).
IMPORTANT SCOPE LIMIT: this package reflects *block assignment*, i.e. which carrier a number range was originally allocated to. It does not account for local number portability. See ACCURACY.md for the expected error rate.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBlobSize = errors.New("linetype: class table has unexpected size")
ErrBlobSize is returned by Validate if the class table is the wrong size.
Functions ¶
func CarrierAvailable ¶
func CarrierAvailable() bool
CarrierAvailable reports whether a carrier table was loaded.
func LoadData ¶ added in v1.0.1
func LoadData() error
LoadData explicitly loads and parses the protobuf data file. It is safe to call from multiple goroutines; the first call does the work.
func MXAvailable ¶
func MXAvailable() bool
MXAvailable reports whether a Mexican range table was loaded.
func RegionAvailable ¶
func RegionAvailable() bool
RegionAvailable reports whether a region table was loaded.
func SetDataPath ¶ added in v1.0.1
func SetDataPath(path string)
SetDataPath configures the path to phone_data.pb. Must be called before any Lookup function. If not called, the path is resolved from LINETYPE_DATA_PATH env var or defaults to data/phone_data.pb relative to the executable.
Types ¶
type Carrier ¶
type Carrier struct {
OCN string // operating company number, e.g. "6529"
Name string // company name as published, e.g. "T-MOBILE USA, INC."
Brand string // optional human-facing name, e.g. "T-Mobile"
}
Carrier identifies the company holding a number range, as published in the assignment data. It is the *block holder*, not the current service provider.
func LookupCarrier ¶
LookupCarrier returns the company holding the range an E.164 +1 number falls in.
func LookupCarrierPrefix ¶
LookupCarrierPrefix is LookupCarrier for a seven-digit NPA-NXX-B prefix.
type Class ¶
type Class uint8
Class is the assignment-derived line type of a number range.
const ( // Unknown means the block is unassigned, or the holding OCN is absent from // the classification map. Never treat Unknown as a synonym for any other // class — abstain instead. Unknown Class = iota Wireline // landline (ILEC, RBOC, traditional fixed-line) Wireless // mobile / cellular (PCS, wireless carriers) VoIP // interconnected VoIP and CLEC-held ranges; frequently SMS-reachable TollFree // toll-free numbers (800, 888, 877, 866, 855, 844, 833) Invalid // structurally not a dialable NANP geographic number )
func Lookup ¶
Lookup returns the assignment-derived class of an E.164 +1 number. It is safe for concurrent use.
Example ¶
c := Lookup("+12025551234")
fmt.Println(c)
fmt.Println(c.SMSReachable())
Output: unknown false
Example (Invalid) ¶
c := Lookup("+442071234567")
fmt.Println(c)
Output: invalid
func LookupPrefix ¶
LookupPrefix returns the class for an already-extracted seven-digit NPA-NXX-B prefix.
func (Class) MarshalText ¶
MarshalText renders the class as its lowercase name for JSON serialisation.
func (Class) SMSReachable ¶
SMSReachable reports whether the class is plausibly able to receive SMS. VoIP counts: a large share of CLEC and interconnected-VoIP ranges are SMS-enabled, and dropping them discards reachable numbers.
Example ¶
fmt.Println(Wireless.SMSReachable()) fmt.Println(VoIP.SMSReachable()) fmt.Println(Wireline.SMSReachable())
Output: true true false
type Number ¶
type Number struct {
Valid bool
Country string // "United States", "Canada", "Mexico"
CountryCode string // "US", "CA", "MX"
E164 string // +18168037763
NPA string // 816
NXX string // 803
Block string // 7
Class Class
SMSReachable bool
Carrier Carrier
Region Region
// contains filtered or unexported fields
}
Number is everything this package knows about one number, assembled from the class, carrier and region tables.
func Describe ¶
Describe assembles everything known about an E.164 +1 or +52 number in one pass. Formatting strings (International, National) are computed lazily via methods to keep the hot path zero-allocation.
Example ¶
n := Describe("+12025551234")
fmt.Println(n.Valid)
fmt.Println(n.NPA)
fmt.Println(n.NXX)
fmt.Println(n.International())
fmt.Println(n.National())
Output: true 202 555 +1 202-555-1234 (202) 555-1234
func (Number) CarrierLabel ¶
CarrierLabel is the name to show a human.
func (Number) International ¶
International returns the E.164 number in international format. For +1: "+1 816-803-7763". For +52: "+52 55 1000 1234".
type Region ¶
type Region struct {
Code string // state or province code, e.g. "MO", "ON"
Name string // full name, e.g. "Missouri", "Ontario"
Country string // e.g. "United States"
CountryCode string // ISO 3166-1 alpha-2, e.g. "US"
}
Region is the geography a number range is assigned to.
func LookupRegion ¶
LookupRegion returns the geography of an E.164 +1 number's NXX.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ltbuild
command
Command ltbuild constructs the packed line-type table from NANPA central office code assignment records, thousands-block pooling records, and an OCN classification map.
|
Command ltbuild constructs the packed line-type table from NANPA central office code assignment records, thousands-block pooling records, and an OCN classification map. |
|
lti
command
Command lti is the Phone Line Type Intelligence CLI.
|
Command lti is the Phone Line Type Intelligence CLI. |
|
examples
|
|
|
basic
command
Example: basic line type lookup for a single number.
|
Example: basic line type lookup for a single number. |
|
csv-classify
command
Example: read a CSV of phone numbers, classify each, and output enriched CSV.
|
Example: read a CSV of phone numbers, classify each, and output enriched CSV. |
|
internal
|
|
|
proto
|
|