Code Monkey home page Code Monkey logo

gouvaddress's Introduction

France

Software License codebeat badge Go Report Card Build Status CircleCI Build Status GoDoc

INSTALLATION

Just use go get github.com/maelsan/gouvaddress and import this package:

import "github.com/maelsan/gouvaddress"

DOCUMENTATION

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(&parameters)
result := gouvaddress.Reverse(&parameters)

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)

Testing

You can test this package with go test github.com/maelsan/gouvaddress. It just checks if a result is returned.

Licence

The MIT License (MIT). Please see License File for more information.

gouvaddress's People

Contributors

maelsan avatar

Watchers

James Cloos avatar Tanguy ⧓ Herrmann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.