Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

loozhengyuan/datagovsg-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data.gov.sg

PkgGoDev Go Report Card ci

Go wrapper for Data.gov.sg real-time APIs.

Datasets

The list of supported datasets are as follows:

Category Dataset Endpoint Supported
Transport Traffic Images /v1/transport/traffic-images
Transport Taxi Availability /v1/transport/taxi-availability
Transport Carpark Availability /v1/transport/carpark-availability
Environment PM2.5 /v1/environment/pm25
Environment PSI /v1/environment/psi
Environment Ultra-violet Index /v1/environment/uv-index
Environment Air Temperature /v1/environment/air-temperature
Environment Rainfall /v1/environment/rainfall
Environment Relative Humidity /v1/environment/relative-humidity
Environment Wind Direction /v1/environment/wind-direction
Environment Wind Speed /v1/environment/wind-speed
Environment 2-hour Weather Forecast /v1/environment/2-hour-weather-forecast
Environment 24-hour Weather Forecast /v1/environment/24-hour-weather-forecast
Environment 4-day Weather Forecast /v1/environment/4-day-weather-forecast
Technology IPOS Design Applications /v1/technology/ipos/designs 🚧
Technology IPOS Trademark Applications /v1/technology/ipos/trademarks 🚧
Technology IPOS Patent Applications /v1/technology/ipos/patents 🚧

Installation

To install the wrapper, use go get to fetch the latest version:

go get -u github.com/loozhengyuan/datagovsg-go/datagovsg

Once installed, import the datagovsg package in your Go application:

import "github.com/loozhengyuan/datagovsg-go/datagovsg"

Usage

For all supported APIs, the wrapper method is accessible using the GetXxx convention. For example, to fetch the latest traffic images, one would call the GetTrafficImages() method.

Fetching the latest data

To illustrate this example, let us assume that we intend fetch the latest traffic images from the API.

package main

import (
	"fmt"

	"github.com/loozhengyuan/datagovsg-go/datagovsg"
)

func main() {
	// Create api client
	c := datagovsg.NewClient()

	// Fetch latest traffic images
	img, _ := c.GetTrafficImages()
	for _, camera := range img.Items {
		for _, images := range camera.Cameras {
			fmt.Println(images.Image)
		}
	}
}

Using the datagovsg.QueryOption

Most APIs allow you to pass a date_time or date parameter to retrieve data at a certain point in time. To do this, one can pass the datagovsg.QueryOption as a variadic argument when calling the respective API methods. Note that the client does not validate these options and will pass them to the API directly.

Using the above example, we will modify the above code to return the traffic images at 2020-05-01T08:03:00 using the date_time parameter:

package main

import (
	"fmt"

	"github.com/loozhengyuan/datagovsg-go/datagovsg"
)

func main() {
	// Create api client
	c := datagovsg.NewClient()

	// Fetch traffic images at point in time
	// using datagovsg.QueryOption
	img, _ := c.GetTrafficImages(
		&datagovsg.QueryOption{
			Key:   "date_time",
			Value: "2020-05-01T08:03:00",
		},
	)
	for _, camera := range img.Items {
		for _, images := range camera.Cameras {
			fmt.Println(images.Image)
		}
	}
}

License

GPL-3.0

All data, including those used as test fixtures and those that you intend to retrieve using this package, are licensed under the Singapore Open Data License. All other aspects of the package is licensed under GPL-3.0.

Releases

No releases published

Packages

No packages published

Languages