Just use go get github.com/maelsan/gouvaddress
and import this package:
import "github.com/maelsan/gouvaddress"
This package use French Governmental Address API which is like a database of addresses in France. Note that those addresses are not affilied to citizens and do not contain personal informations. This API returns addresses referenced in France.
I only implemented /search/
& /reverse/
because CSV format is too old, deprecated and so awful that I cannot imagine use it with a modern API. You must define a map of your parameters, like this:
parameters := map[string]string{
"q": "8 bd du port",
"lat": "48.357",
"lon": "2.37",
}
And call the function which correspond to the API endpoint.
result := gouvaddress.Search(¶meters)
result := gouvaddress.Reverse(¶meters)
The returns value is a struct named JSON
, here is her composition:
type JSON struct {
Limit int `json:"limit"`
Attribution string `json:"attribution"`
Version string `json:"version"`
Licence string `json:"licence"`
Query string `json:"query"`
Type string `json:"type"`
Features []struct {
Geometry struct {
Type string `json:"type"`
Coordinates []float64 `json:"coordinates"`
} `json:"geometry"`
Properties struct {
Citycode string `json:"citycode"`
Postcode string `json:"postcode"`
Name string `json:"name"`
Housenumber string `json:"housenumber"`
Type string `json:"type"`
Context string `json:"context"`
Score float64 `json:"score"`
Label string `json:"label"`
City string `json:"city"`
ID string `json:"id"`
Street string `json:"street"`
Distance int `json:"distance"`
} `json:"properties"`
Type string `json:"type"`
} `json:"features"`
}
Voilà! You can access to your result as a standard struct, for example:
// Be careful with types, all objects in gouvaddress haven't the same type.
fmt.Printf("%s", result.Query)
fmt.Printf("%d", result.Limit)
// Some objects are substructs or substruct-arrays (so you can use loop or others...).
fmt.Printf("%s", result.Features[0].Properties.City)
fmt.Printf("%d", result.Features[0].Properties.Distance)
You can test this package with go test github.com/maelsan/gouvaddress
. It just checks if a result is returned.
The MIT License (MIT). Please see License File for more information.