Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Abbreviation ¶
type Abbreviation string
Abbreviation represents a two-letter abbreviation for a territory in the North American Numbering Plan.
func Abbreviations ¶
func Abbreviations() []Abbreviation
Abbreviations returns a list of all two-letter abbreviations for territories in the North American Numbering Plan sorted in ascending order.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { codes := areacode.Abbreviations() fmt.Println(codes[0]) }
Output: AB
type NAN ¶
type NAN int
NAN represents a North American Numbering Plan area code.
func AreaCodes ¶
func AreaCodes() []NAN
AreaCodes returns a list of all NANP area codes sorted in ascending order.
func (NAN) HTML ¶
HTML returns the NANP code as an HTML span element.
Example:
212 - New York (NY)
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { fmt.Println(areacode.NAN(403).HTML()) }
Output: <span>403 - Alberta (AB) + Yukon (YT)</span><br>
type Result ¶
Result represents the result of a query, which can be an area code or a list of territories.
func Queries ¶
Queries returns a list of results for multiple queries from a form input.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { q := areacode.Queries("az", "arizona", "ut", "602") for _, result := range q { s := result.AreaCode.HTML() if s != "" { fmt.Println(s) } for _, t := range result.Terr { fmt.Println(t.HTML()) } } }
Output: <span>Arizona (AZ) - 602</span><br> <span>Arizona (AZ) - 602</span><br> <span>Utah (UT) - 801</span><br> <span>602 - Arizona (AZ)</span><br>
func Query ¶
Query returns the result of a query from a form input.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { fmt.Println(areacode.Query("az").Terr) fmt.Println(areacode.Query("arizona").Terr[0].HTML()) fmt.Println(areacode.Query("ut").Terr[0].HTML()) fmt.Println(areacode.Query("602").AreaCode.HTML()) }
Output: [{Arizona AZ [602]}] <span>Arizona (AZ) - 602</span><br> <span>Utah (UT) - 801</span><br> <span>602 - Arizona (AZ)</span><br>
type Territory ¶
type Territory struct { Name string // Name of the state, province, or territory. Abbreviation Abbreviation // Two-letter abbreviation. AreaCodes []NAN // Three-digit NAN code used for telephone area codes. }
Territory represents a territory in the North American Numbering Plan.
func Lookup ¶
Lookup returns a list of territories that match the given input. The input can be a string, integer, or NAN. If the input is a string, it will match against territory names and abbreviations. If the input is an integer, it will match against NANP codes.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { t := areacode.Lookup("texas") fmt.Println(t[0]) t = areacode.Lookup("tx") fmt.Println(t[0]) t = areacode.Lookup(214) fmt.Println(t[0]) }
Output: {Texas TX [210 214 409 512 713 806 817 903 915]} {Texas TX [210 214 409 512 713 806 817 903 915]} {Texas TX [210 214 409 512 713 806 817 903 915]}
func Lookups ¶
Lookup returns a list of territories that match the given inputs.
See Lookup for more information.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { t := areacode.Lookups(817, "iowa", 202) for _, v := range t { fmt.Println(v) } }
Output: {Texas TX [210 214 409 512 713 806 817 903 915]} {Iowa IA [319 515 712]} {District of Columbia DC [202]}
func Territories ¶
func Territories() []Territory
Territories returns a list of all territories in the North American Numbering Plan sorted by name in ascending order.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { t := areacode.Territories() name := t[0].Name alpha := t[0].Abbreviation area := t[0].AreaCodes fmt.Printf("%s %s %d\n", name, alpha, area) fmt.Println(len(t), "territories") }
Output: Alabama AL [205] 66 territories
func TerritoryByAbbr ¶
func TerritoryByAbbr(abbr Abbreviation) Territory
TerritoryByAbbr returns the territory with the given two-letter abbreviation.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { t := areacode.TerritoryByAbbr("CT") fmt.Println(t.Name, t.Abbreviation, t.AreaCodes) }
Output: Connecticut CT [203]
func TerritoryByCode ¶
TerritoryByCode returns the territories for the given North American Numbering code.
Generally, this will return a single territory, but it is possible for a NAN code to be used in multiple territories, such as provinces in Canada.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { t := areacode.TerritoryByCode(212) fmt.Println(t[0].Name, t[0].Abbreviation, t[0].AreaCodes) t = areacode.TerritoryByCode(902) for _, v := range t { fmt.Println(v.Name, v.Abbreviation, v.AreaCodes) } }
Output: New York NY [212 315 516 518 607 716 718 914 917] Nova Scotia NS [902] Prince Edward Island PE [902]
func TerritoryByName ¶
TerritoryByName returns the territory with the given name. The name can be a US state, Canadian province, or other territory.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { t := areacode.TerritoryByName("ontario") fmt.Println(t.AreaCodes) }
Output: [416 519 613 705 807 905]
func TerritoryContains ¶
TerritoryContains returns a list of territories with names that contain the given string.
Example ¶
package main import ( "fmt" "github.com/Defacto2/server/handler/areacode" ) func main() { t := areacode.TerritoryContains("south") for _, v := range t { fmt.Println(v) } }
Output: {South Carolina SC [803]} {South Dakota SD [605]}