carlqt
3/13/2017 - 11:23 PM

bus.go

package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
)

func main() {
	busKey := os.Getenv("ACCOUNT_KEY")
	// googleServerKey := os.Getenv("GOOGLE_SERVER_KEY")
	ltaUserKey := "3f8e685f-1505-4fe1-9b70-f08f8e8f3cbe"
	url := "http://datamall2.mytransport.sg/ltaodataservice/BusStops?$skip=13"

	client := &http.Client{}
	req, _ := http.NewRequest("GET", url, nil)
	req.Header.Set("UniqueUserID", ltaUserKey)
	req.Header.Set("AccountKey", busKey)
	req.Header.Set("Accept", "application/json")

	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}

	defer resp.Body.Close()

	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println("response Body:", string(body))
}