Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bombsimon/swedish-zipcode
📬 Validation package in Go for Swedish zip codes
https://github.com/bombsimon/swedish-zipcode
postal-codes swedish zip zip-code zip-codes
Last synced: 17 days ago
JSON representation
📬 Validation package in Go for Swedish zip codes
- Host: GitHub
- URL: https://github.com/bombsimon/swedish-zipcode
- Owner: bombsimon
- License: mit
- Created: 2019-01-16T08:23:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-20T15:05:19.000Z (about 5 years ago)
- Last Synced: 2024-10-20T21:43:16.950Z (about 2 months ago)
- Topics: postal-codes, swedish, zip, zip-code, zip-codes
- Language: Go
- Homepage:
- Size: 61.5 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-sweden - Go
README
# Swedish Zipcode
This package provides validation for Swedish zip codes (or postal codes) based
on the provided [CSV](sweden-zipcode.csv). The CSV was generated at 2019-01-19
by traversing the Bring API described below between `10000` and `99999`.## HTTPS fallback
Since there're constantly changes in zip codes in Sweden a lot of them are
missing in the CSV submodule. This package supports the possibiity to fallback
to an [HTTPS API from Bring](https://developer.bring.com/api/postal-code/).If you call `Store()` on the `ZipCodes` type you can store all newly found zip
codes in the existing CSV file for faster and offline execution in the future.## Multiple results
A few zip codes are listed as multiple matches which means they're shared
between multiple locations. Instead of choosing one of them none is chosen so
to see which these are you can use `grep ',$' sweden-zipcode.csv`.**Example**
```
set ex (grep ',$' sweden-zipcode.csv | string sub --length 5 | head -1); \
curl -sL \
"https://api.bring.com/shippingguide/api/postalCode.json?clientUrl=ex&country=SE&pnr=$ex" \
| jq .multipleMatches[
"Södertälje",
"Enhörna"
]
```## Examples
```go
// One time validation
sz.Valid("12010") // true
sz.Valid(12010) // true// Multiple validations - create a cache
httpFallback := true
zc := sz.NewZipCodes(httpFallback)
zc.ClientURL("https://my.url.se")zc.Valid("12010") // true
zc.Valid(12010) // true
zc.Valid(99999) // falsezc.Store() // Updates the CSV file with new zip codes.
```