Skip to content

Commit

Permalink
Rename to geozip
Browse files Browse the repository at this point in the history
  • Loading branch information
ngrash committed Dec 20, 2023
1 parent 3fd053f commit 32b0cd7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Postcode
# Geozip

## Overview
The `postcode` package is designed for fetching and parsing postal code data, specifically from the GeoNames geographical database (https://www.geonames.org/).
The `geozip` package is designed for fetching and parsing postal code data, specifically from the GeoNames geographical database (https://www.geonames.org/).
It offers a straightforward interface to download postal code data for various countries and parse them into a structured Go data type.

## Features
Expand All @@ -13,7 +13,7 @@ It offers a straightforward interface to download postal code data for various c
To use the `postcode` package in your Go project, simply execute the following command:

```bash
go get github.com/ngrash/postcode
go get github.com/ngrash/geozip
```

## Usage
Expand All @@ -25,11 +25,11 @@ Example:
```go
package main

import "github.com/ngrash/postcode"
import "github.com/ngrash/geozip"

func main() {
var previousEtag string
entries, modified, newEtag, err := postcode.FetchCountry("US", previousEtag)
entries, modified, newEtag, err := geozip.FetchCountry("US", previousEtag)
if err != nil {
// Handle error
}
Expand Down
4 changes: 2 additions & 2 deletions postcode.go → geozip.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package postcode provides functionality specifically for downloading and parsing
// Package geozip provides functionality specifically for downloading and parsing
// postal code data from the GeoNames geographical database (https://www.geonames.org/).
package postcode
package geozip

import (
"archive/zip"
Expand Down
36 changes: 18 additions & 18 deletions postcode_test.go → geozip_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package postcode_test
package geozip_test

import (
"github.com/ngrash/postcode"
"github.com/ngrash/geozip"
"net/http"
"os"
"testing"
Expand All @@ -15,7 +15,7 @@ func (fn RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

func TestFetchCountry_NotModified(t *testing.T) {
const requestEtag = "current_etag"
postcode.HTTPClient.Transport = RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
geozip.HTTPClient.Transport = RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
if got, want := r.URL.String(), "https://download.geonames.org/export/zip/DE.zip"; got != want {
t.Errorf("client requested %q, want %q", got, want)
}
Expand All @@ -29,7 +29,7 @@ func TestFetchCountry_NotModified(t *testing.T) {
StatusCode: http.StatusNotModified,
}, nil
})
entries, modified, newEtag, err := postcode.FetchCountry("de", requestEtag)
entries, modified, newEtag, err := geozip.FetchCountry("de", requestEtag)
if entries != nil {
t.Errorf("entries = %v, want nil", entries)
}
Expand All @@ -49,7 +49,7 @@ func TestFetchCountry_Modified(t *testing.T) {
requestEtag = "old_etag"
responseEtag = "new_etag"
)
postcode.HTTPClient.Transport = RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
geozip.HTTPClient.Transport = RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
if got, want := r.URL.String(), "https://download.geonames.org/export/zip/DE.zip"; got != want {
t.Errorf("client requested %q, want %q", got, want)
}
Expand All @@ -71,7 +71,7 @@ func TestFetchCountry_Modified(t *testing.T) {
},
}, nil
})
entries, modified, newEtag, err := postcode.FetchCountry("de", requestEtag)
entries, modified, newEtag, err := geozip.FetchCountry("de", requestEtag)
if got, want := len(entries), 16477; got != want {
t.Errorf("len(entries) = %v, want %v", got, want)
}
Expand All @@ -96,40 +96,40 @@ func TestFetchCountry_Modified(t *testing.T) {
idx := line - 1
entry := entries[idx]

if got, want := entry[postcode.CountryCode], fields[0]; got != want {
if got, want := entry[geozip.CountryCode], fields[0]; got != want {
t.Errorf("entries[%d]: CountryCode = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.PostalCode], fields[1]; got != want {
if got, want := entry[geozip.PostalCode], fields[1]; got != want {
t.Errorf("entries[%d]: PostalCode = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.PlaceName], fields[2]; got != want {
if got, want := entry[geozip.PlaceName], fields[2]; got != want {
t.Errorf("entries[%d]: PlaceName = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.AdminName1], fields[3]; got != want {
if got, want := entry[geozip.AdminName1], fields[3]; got != want {
t.Errorf("entries[%d]: AdminName1 = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.AdminCode1], fields[4]; got != want {
if got, want := entry[geozip.AdminCode1], fields[4]; got != want {
t.Errorf("entries[%d]: AdminCode1 = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.AdminName2], fields[5]; got != want {
if got, want := entry[geozip.AdminName2], fields[5]; got != want {
t.Errorf("entries[%d]: AdminName2 = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.AdminCode2], fields[6]; got != want {
if got, want := entry[geozip.AdminCode2], fields[6]; got != want {
t.Errorf("entries[%d]: AdminCode2 = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.AdminName3], fields[7]; got != want {
if got, want := entry[geozip.AdminName3], fields[7]; got != want {
t.Errorf("entries[%d]: AdminName3 = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.AdminCode3], fields[8]; got != want {
if got, want := entry[geozip.AdminCode3], fields[8]; got != want {
t.Errorf("entries[%d]: AdminCode3 = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.Latitude], fields[9]; got != want {
if got, want := entry[geozip.Latitude], fields[9]; got != want {
t.Errorf("entries[%d]: Latitude = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.Longitude], fields[10]; got != want {
if got, want := entry[geozip.Longitude], fields[10]; got != want {
t.Errorf("entries[%d]: Longitude = %v, want %v", idx, got, want)
}
if got, want := entry[postcode.Accuracy], fields[11]; got != want {
if got, want := entry[geozip.Accuracy], fields[11]; got != want {
t.Errorf("entries[%d]: Accuracy = %v, want %v", idx, got, want)
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/ngrash/postcode
module github.com/ngrash/geozip

go 1.21

0 comments on commit 32b0cd7

Please sign in to comment.