Categorygithub.com/hendler/gozipcode
modulepackage
0.0.0-20170707222730-730b1d0d0749
Repository: https://github.com/hendler/gozipcode.git
Documentation: pkg.go.dev

# README

gozipcode

US ZipCode database, batteries included.

go port of https://github.com/buckmaxwell/zipcode

 go get github.com/Hendler/gozipcode

usage

Building the example

go build -o $GOBIN/gozipcode-example example/main.go

import (
    "github.com/Hendler/gozipcode"
    "fmt"
)

func main(){
    gozipcode.Init()
    fmt.Print("EXACT MATCH --- \n")
    zipcode := gozipcode.Isequal("04976")
    fmt.Printf("%v\n", *zipcode)
    zipcode = gozipcode.Isequal("adsfa")
    if (zipcode != nil){
        fmt.Printf("%v\n", *zipcode)
    }

    fmt.Print("PREFIX --- \n")
    zipcodes := gozipcode.Islike("0497%")
    for _, zipcode := range zipcodes {
        fmt.Printf("%v\n", *zipcode)
    }

    fmt.Print("RADIUS --- \n")
    skow_lat  := 44.77
    skow_long := -69.71
    zipcodes = gozipcode.Isinradius(skow_lat, skow_long, 15)
    for _, zipcode := range zipcodes {
        fmt.Printf("%v\n", *zipcode)
    }
}

TODO

  • zipcodes for all countries
  • more tests
  • configurable database location
  • performance - confirm that check_same_thread is doing something useful
  • use sql.NullString in struct

building

gozipcode optionally uses Glide (glide.lock, glide.yaml file inculded, vendor directory ommitted)

go get github.com/Masterminds/glide
go install github.com/Masterminds/glide

glide install

dependencies

In glide.yaml

github.com/mattn/go-sqlite3

investigate

github.com/golang/geo

notes

SQLite file is included in Binary via bindata

go get -u github.com/jteeuwen/go-bindata
go install github.com/jteeuwen/go-bindata
go-bindata -pkg gozipcode -o ./data/zipcode.go ./data/zipcode.db

# Packages

No description provided by the author

# Functions

No description provided by the author
* The haversine formula will calculate the spherical distance as the crow flies * between lat and lon for two given points in km * from https://play.golang.org/p/MZVh5bRWqN func main() { var locationName [2]string var location [2][2]float64 // York - lat,lon locationName[0] = "York" location[0][0] = 1.0803 location[0][1] = 53.9583 // Bristol - lat,lon locationName[1] = "Bristol" location[1][0] = 2.5833 location[1][1] = 51.4500 // Use haversine to get the resulting diatance between the two values var distance = Haversine(location[0][0], location[0][1], location[1][0], location[1][1]) // We wish to use miles so will alter the resulting distance var distancemiles = distance * kmtomiles fmt.Printf("The distance between %s and %s is %.02f miles as the crow flies", locationName[0], locationName[1], distancemiles) } */.
Init is called automatically by each function can be called explicitly.
No description provided by the author
No description provided by the author
Takes a partial zip code and returns a list of zipcode objects with matching prefixes.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author

# Structs