Skip to content

Hendler/gozipcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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