Skip to content

Instantly share code, notes, and snippets.

Last active Dec 17, 2015
What would you like to do?
Query the JCDecaux Vélib' API for a station Id
package main
import (
func main() {
stationId := os.Args[1]
// You need to change that API KEY. Get it here:
const yourApiKey = "ae55d65e9bbe2bf740c7fbd3915d583d3aa"
res, err := http.Get("" + stationId + "?contract=Paris&apiKey=" + yourAp
if err != nil {
stationsBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
// We don't know the JSON "schema", let's get a generic way
var jsonstations interface{}
jsonerr := json.Unmarshal(stationsBytes, &jsonstations)
if jsonerr != nil {
m := jsonstations.(map[string]interface{})
for k, v := range m {
switch vv := v.(type) {
case string:
fmt.Println(k, "is string:", vv)
case int:
fmt.Println(k, "is int:", vv)
case float64:
fmt.Println(k, "is float64:", vv)
case []interface{}:
fmt.Println(k, "is an array:")
for i, u := range vv {
fmt.Println(i, u)
case map[string]interface{}:
fmt.Println(k, "is a map:")
for i, u := range vv {
fmt.Println(i, u)
case bool:
fmt.Println(k, "is a bool:", vv)
fmt.Println(k, "is of a type I don't know how to handle")
Copy link

fclairamb commented Jul 13, 2014

Un petit coup de "go fmt" ne ferait pas de mal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment