{"id":47689310,"url":"https://github.com/matnich89/network-rail-client","last_synced_at":"2026-04-02T15:17:49.924Z","repository":{"id":248913555,"uuid":"830142144","full_name":"matnich89/network-rail-client","owner":"matnich89","description":"A Go Client for consuming real time data from Network Rails STOMP Data feeds","archived":false,"fork":false,"pushed_at":"2024-08-22T17:02:57.000Z","size":35,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-01T09:21:51.495Z","etag":null,"topics":["asynchronous-programming","go","high-performance","train-information","trains"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matnich89.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-17T17:14:51.000Z","updated_at":"2024-08-19T17:08:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"fb002974-991c-407d-ad6a-2092a0285b04","html_url":"https://github.com/matnich89/network-rail-client","commit_stats":null,"previous_names":["matnich89/network-rail-client"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/matnich89/network-rail-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matnich89%2Fnetwork-rail-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matnich89%2Fnetwork-rail-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matnich89%2Fnetwork-rail-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matnich89%2Fnetwork-rail-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matnich89","download_url":"https://codeload.github.com/matnich89/network-rail-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matnich89%2Fnetwork-rail-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31308863,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous-programming","go","high-performance","train-information","trains"],"created_at":"2026-04-02T15:17:49.213Z","updated_at":"2026-04-02T15:17:49.907Z","avatar_url":"https://github.com/matnich89.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Network Rail Client\n\nThis Go package provides a client for connecting to and consuming data from the Network Rail data feeds. It handles\nReal-Time Public Performance Measure (RTPPM) and Train Movement data feeds.\n\n## Installation\n\nTo use this package in your Go project, run:\n\n```bash\ngo get github.com/matnich89/network-rail-client\n```\n\n## Features\n\n* Easy connection to Network Rail's STOMP server\n* Automatic handling of subscription and message parsing for multiple data feeds\n* Support for subscribing to all train movements or specific train operating companies\n* Graceful shutdown and resource cleanup\n* Error handling through a dedicated error channel\n\n## API\n\n### `NewNetworkRailClient(ctx context.Context, username, password string) (*NetworkRailClient, error)`\n\nCreates a new Network Rail client and establishes a connection to the STOMP server.\n\n### `(nr *NetworkRailClient) SubRTPPM() (chan *realtime.RTPPMDataMsg, error)`\n\nSubscribes to the RTPPM feed and returns a channel of RTPPM messages.\n\n### `(nr *NetworkRailClient) SubAllTrainMovement() (\u003c-chan movement.Body, error)`\n\nSubscribes to all train movement messages and returns a channel of movement data.\n\n### `(nr *NetworkRailClient) SubMultiTrainCompanyMovements(operators []model.TrainOperator) ([]*TrainCompanySub, error)`\n\nSubscribes to train movement messages for specific train operating companies and returns a slice of TrainCompanySub\nstructures, each containing a channel for that company's movement data.\n\n## Data Models\n\nThe package includes several data models:\n\n* `realtime.RTPPMDataMsg`: Represents the RTPPM data structure.\n* `movement.Body`: Interface for different types of train movement messages.\n* `model.TrainOperator`: Represents a train operating company.\n\n## Usage\n\nHere's a basic example of how to use the client:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"os/signal\"\n\t\"sync\"\n\t\"syscall\"\n\n\t\"github.com/matnich89/network-rail-client/client\"\n\t\"github.com/matnich89/network-rail-client/model\"\n\t\"github.com/matnich89/network-rail-client/model/movement\"\n\t\"github.com/matnich89/network-rail-client/model/realtime\"\n)\n\nfunc main() {\n\t// Replace with your actual Network Rail API credentials (MAKE SURE TO USE EMV VARS!!!)\n\tusername := \"your-username\"\n\tpassword := \"your-password\"\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\t// Create a new NetworkRailClient\n\tnrClient, err := client.NewNetworkRailClient(ctx, username, password)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create NetworkRailClient: %v\", err)\n\t}\n\n\t// Create a WaitGroup to manage our goroutines\n\tvar wg sync.WaitGroup\n\n\t// Subscribe to RTPPM data\n\trtppmChan, err := nrClient.SubRTPPM()\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to subscribe to RTPPM: %v\", err)\n\t}\n\n\t// Subscribe to all train movements\n\tallMovementsChan, err := nrClient.SubAllTrainMovement()\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to subscribe to all train movements: %v\", err)\n\t}\n\n\t// Subscribe to specific train company movements\n\toperators := []model.TrainOperator{\n\t\tmodel.ElizabethLine,\n\t\tmodel.CrossCountry,\n\t}\n\tcompanySubChannels, err := nrClient.SubMultiTrainCompanyMovements(operators)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to subscribe to company-specific movements: %v\", err)\n\t}\n\n\t// Set up a channel to handle shutdown gracefully\n\tshutdown := make(chan os.Signal, 1)\n\tsignal.Notify(shutdown, os.Interrupt, syscall.SIGTERM)\n\n\t// Start goroutines to handle incoming data\n\twg.Add(1)\n\tgo handleRTPPM(ctx, \u0026wg, rtppmChan)\n\twg.Add(1)\n\tgo handleAllMovements(ctx, \u0026wg, allMovementsChan)\n\tfor _, companySub := range companySubChannels {\n\t\twg.Add(1)\n\t\tgo handleCompanyMovements(ctx, \u0026wg, companySub)\n\t}\n\n\t// Handle errors\n\twg.Add(1)\n\tgo func() {\n\t\tdefer wg.Done()\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase err := \u003c-nrClient.ErrCh:\n\t\t\t\tlog.Printf(\"Error: %v\", err)\n\t\t\tcase \u003c-ctx.Done():\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\n\t// Wait for shutdown signal\n\t\u003c-shutdown\n\tfmt.Println(\"Shutting down...\")\n\tcancel()\n\n\t// Wait for all goroutines to finish\n\twg.Wait()\n\tfmt.Println(\"Shutdown complete\")\n}\n\nfunc handleRTPPM(ctx context.Context, wg *sync.WaitGroup, rtppmChan \u003c-chan *realtime.RTPPMDataMsg) {\n\tdefer wg.Done()\n\tfor {\n\t\tselect {\n\t\tcase msg := \u003c-rtppmChan:\n\t\t\tfmt.Printf(\"Received RTPPM data: %+v\\n\", msg)\n\t\tcase \u003c-ctx.Done():\n\t\t\treturn\n\t\t}\n\t}\n}\n\nfunc handleAllMovements(ctx context.Context, wg *sync.WaitGroup, movementsChan \u003c-chan movement.Body) {\n\tdefer wg.Done()\n\tfor {\n\t\tselect {\n\t\tcase movement := \u003c-movementsChan:\n\t\t\tfmt.Printf(\"Received movement: %+v\\n\", movement)\n\t\tcase \u003c-ctx.Done():\n\t\t\treturn\n\t\t}\n\t}\n}\n\nfunc handleCompanyMovements(ctx context.Context, wg *sync.WaitGroup, companySub *client.TrainCompanySub) {\n\tdefer wg.Done()\n\tfor {\n\t\tselect {\n\t\tcase movement := \u003c-companySub.SubChan:\n\t\t\tfmt.Printf(\"Received %s movement: %+v\\n\", companySub.Name, movement)\n\t\tcase \u003c-ctx.Done():\n\t\t\treturn\n\t\t}\n\t}\n}\n\n```\n\n## Dependencies\n\n* github.com/go-stomp/stomp/v3\n\n## License\n\nMIT License\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Disclaimer\n\nThis client is unofficial and is not affiliated with Network Rail. Users must comply with Network Rail's terms of\nservice when using this client.\n\n## Resources\n\nFor Network Rail data-feed info, check out\nthe [Network Rail Open Data Feeds](https://www.networkrail.co.uk/who-we-are/transparency-and-ethics/transparency/open-data-feeds/)\npage.\n\nFor documents on how to interact with the feeds, visit\nthe [Open Rail Wiki](https://wiki.openraildata.com/index.php?title=Main_Page).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatnich89%2Fnetwork-rail-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatnich89%2Fnetwork-rail-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatnich89%2Fnetwork-rail-client/lists"}