This package aims to simplify and provide a Golang interface for interacting with Singapore's Bus API. More information about the API can be located inside the documentation here.
The API is subjected to changes from time to time (depends on MyTransport), so it is not always possible to keep this wrapper up-to-date. That being said, I will still try my best to maintain this repository.
Before using this wrapper, the first step will be to request for an API key from MyTransport, which can be located here. If the provided link is broken due to some unknown reasons, the link to the registration page should still be easy to locate in their home page.
Under MyTransport services, there are many endpoints, but not all of them are currently present inside this Golang wrapper. In future, I am intending to support more endpoints and ideally, it should be all of them.
- Bus Arrivals
- Bus Services
- Bus Routes
- Bus Stops
For in-depth details on each endpoint, you should visit their documentation to find out more. Alternatively, you may refer to model/response.go
for the struct
of each endpoint's response.
- Install the package
go get github.com/LeonLyx/sg-bus-api
- Import the library into your codebase
import (
"github.com/LeonLyx/sg-bus-api/api"
)
- Begin to write code
client := api.NewBusAPIClient("<your-api-key-here>")
busArrival, err := client.GetBusArrival("83139", "15")
For more examples, please refer to main.go
. If you are unsure about the struct
implementation for the corresponding endpoint's response, do refer to model/response.go
.
- Clone this repository
git clone https://github.com/LeonLyx/sg-bus-api.git
- Navigate to the project directory
cd sg-bus-api/
- Build and run
main.go
go build
./sg-bus-api --account-key <your-api-key-here>
As mentioned, it is not quite possible to be updated with the services provided by MyTransport. I am hoping to have a collaboration with a group of interested developers. If you would like to extend a helping hand, do hit me up at [email protected]. Thank you in advance!