Перейти к содержанию

Golang GTFS-realtime Language Bindings

Provides Golang structs generated from the GTFS-realtime Protocol Buffer specification. These structs will allow you to parse a binary Protocol Buffer GTFS-realtime data feed into Golang objects.

Add the Dependency

To use the gtfs-realtime-bindings structs in your own project, you need to first install this library with:

go get github.com/MobilityData/gtfs-realtime-bindings/golang/gtfs

And install the golang protobuf library dependency with:

go get github.com/golang/protobuf/proto

Example Code

The following code snippet demonstrates downloading a GTFS-realtime data feed from a particular URL, parsing it as a FeedMessage (the root type of the GTFS-realtime schema), and iterating over the results.

package main

import (
    proto "github.com/golang/protobuf/proto"

func main() {
    var (
        username = "YOUR_ACCESS_KEY"
        password = "YOUR_SECRET_KEY"

    client := &http.Client{}
    req, err := http.NewRequest("GET", "URL OF YOUR GTFS-REALTIME SOURCE GOES HERE", nil)
    req.SetBasicAuth(username, password)
    resp, err := client.Do(req)
    defer resp.Body.Close()
    if err != nil {
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {

    feed := gtfs.FeedMessage{}
    err = proto.Unmarshal(body, &feed)
    if err != nil {

    for _, entity := range feed.Entity {
        tripUpdate := entity.TripUpdate
        trip := tripUpdate.Trip
        tripId := trip.TripId
        fmt.Printf("Trip ID: %s\n", *tripId)

For more details on the naming conventions for the Golang structs generated from the gtfs-realtime.proto, check out the Golang Generated Code section of the Protocol Buffers developer site.