Documentation
¶
Overview ¶
Package dvb provides a Go client for interacting with the Dresden Transport (DVB) API. It allows you to fetch real-time public transport information including departures, routes, lines, and stop information for Dresden's public transportation network.
Example usage:
client := dvb.NewClient(dvb.Config{})
response, err := client.MonitorStop(ctx, &dvb.MonitorStopParams{
StopId: "33000028", // Dresden Hauptbahnhof
})
Index ¶
- type Client
- func (c *Client) GetLines(ctx context.Context, options *GetLinesParams) (*GetLinesResponse, error)
- func (c *Client) GetPoint(ctx context.Context, options *GetPointParams) (*GetPointResponse, error)
- func (c *Client) GetRoute(ctx context.Context, options *GetRouteParams) (*GetRouteResponse, error)
- func (c *Client) MonitorStop(ctx context.Context, options *MonitorStopParams) (*MonitorStopResponse, error)
- type Config
- type Departure
- type Direction
- type Diva
- type GetLinesParams
- type GetLinesResponse
- type GetPointParams
- type GetPointResponse
- type GetRouteParams
- type GetRouteResponse
- type Line
- type MonitorStopParams
- type MonitorStopResponse
- type Mot
- type MotChain
- type PartialRoute
- type Platform
- type RegularStop
- type Route
- type Status
- type Ticket
- type TimeTable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a DVB API client with configuration for making requests.
func NewClient ¶
NewClient creates a new DVB API client with the provided configuration. If no configuration is provided, sensible defaults will be used.
func (*Client) GetLines ¶
func (c *Client) GetLines(ctx context.Context, options *GetLinesParams) (*GetLinesResponse, error)
GetLines retrieves a list of all public transport lines that serve a specific stop. This function is useful for discovering which buses, trams, and trains are available at a particular stop, along with their destinations and timetable information.
The response includes comprehensive information about each line including the mode of transport, available directions, and timetable variants. This information is essential for journey planning and understanding transport options at any given stop.
Parameters:
- ctx: Context for the request, allowing for cancellation and timeouts
- options: Parameters including the required stop ID and optional format specification
Returns:
- *GetLinesResponse: Contains the list of lines and metadata
- error: Returns an error if the stop ID is empty or if the API request fails
Example usage:
params := &GetLinesParams{
StopId: "33000037",
}
response, err := client.GetLines(ctx, params)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Lines serving this stop:\n")
for _, line := range response.Lines {
fmt.Printf("Line %s (%s):\n", line.Name, line.Mot)
for _, direction := range line.Directions {
fmt.Printf(" → %s\n", direction.Name)
}
}
func (*Client) GetPoint ¶
func (c *Client) GetPoint(ctx context.Context, options *GetPointParams) (*GetPointResponse, error)
GetPoint searches for public transport stops, stations, and points of interest using the DVB point finder API. This is typically the first step when looking up public transport information, as you need stop IDs for other API calls.
The function performs a search based on the provided query string and returns matching points. The search can be refined using various optional parameters to filter results by type, provider, or limit the number of results.
Parameters:
- ctx: Context for the request, allowing for cancellation and timeouts
- options: Search parameters including the required query string and optional filters
Returns:
- *GetPointResponse: Contains the search results and metadata
- error: Returns an error if the query is empty or if the API request fails
Example usage:
params := &GetPointParams{
Query: "Hauptbahnhof",
StopsOnly: &[]bool{true}[0],
Limit: &[]int{5}[0],
}
response, err := client.GetPoint(ctx, params)
if err != nil {
log.Fatal(err)
}
for _, point := range response.Points {
fmt.Println("Found point:", point)
}
func (*Client) GetRoute ¶
func (c *Client) GetRoute(ctx context.Context, options *GetRouteParams) (*GetRouteResponse, error)
GetRoute plans a journey between two locations using public transport. This function provides comprehensive trip planning including multiple route options, timing information, transfer details, and pricing for Dresden's public transport network.
The function returns multiple route alternatives with detailed step-by-step instructions, real-time information (when available), and complete fare information. This is the primary function for journey planning and route discovery.
Parameters:
- ctx: Context for the request, allowing for cancellation and timeouts
- options: Trip planning parameters including required origin and destination, plus optional timing and routing preferences
Returns:
- *GetRouteResponse: Contains multiple route options with detailed journey information
- error: Returns an error if origin or destination is empty, or if the API request fails
Example usage:
params := &GetRouteParams{
Origin: "Hauptbahnhof",
Destination: "Neustadt Bahnhof",
ShortTermChanges: &[]bool{true}[0],
}
response, err := client.GetRoute(ctx, params)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d route options:\n", len(response.Routes))
for i, route := range response.Routes {
fmt.Printf("Route %d: %d minutes, %d transfers, Price: %s\n",
i+1, route.Duration, route.Interchanges, route.Price)
}
func (*Client) MonitorStop ¶
func (c *Client) MonitorStop(ctx context.Context, options *MonitorStopParams) (*MonitorStopResponse, error)
MonitorStop retrieves real-time departure and arrival information for a specific stop. This function is used to monitor when buses, trams, and trains will leave or arrive at a particular stop, including real-time updates about delays and cancellations.
The function provides comprehensive information about each departure including line details, timing, platform information, and any service disruptions. This is essential for passengers who want to know when their next transport will arrive.
Parameters:
- ctx: Context for the request, allowing for cancellation and timeouts
- options: Monitoring parameters including the required stop ID and optional filters
Returns:
- *MonitorStopResponse: Contains the departure/arrival information and metadata
- error: Returns an error if the stop ID is empty or if the API request fails
Example usage:
params := &MonitorStopParams{
StopId: "33000037",
Limit: &[]int{10}[0],
ShortTermChanges: &[]bool{true}[0],
}
response, err := client.MonitorStop(ctx, params)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Departures from %s:\n", response.Name)
for _, dep := range response.Departures {
fmt.Printf("Line %s to %s: %s\n", dep.LineName, dep.Direction, dep.RealTime)
}
type Config ¶
type Config struct {
BaseURL string // Base URL for the DVB API (optional, defaults to official API)
UserAgent string // User agent string for requests (optional)
Timeout time.Duration // HTTP timeout for requests (optional, defaults to 30s)
HTTPClient *http.Client // Custom HTTP client (optional)
}
Config holds configuration options for creating a new DVB client.
type Departure ¶
type Departure struct {
// Id is the unique identifier for this departure
Id string `json:"Id"`
// DlId is the DVB line identifier
DlId string `json:"DlId"`
// LineName is the display name of the public transport line (e.g., "11", "85", "S1")
LineName string `json:"LineName"`
// Direction indicates the destination or direction of the vehicle
Direction string `json:"Direction"`
// Platform contains information about the platform or stop position
Platform Platform `json:"Platform"`
// Mot indicates the mode of transport (e.g., "Tram", "Bus", "S-Bahn")
Mot string `json:"Mot"`
// RealTime is the actual departure/arrival time including delays
RealTime string `json:"RealTime"`
// ScheduledTime is the originally planned departure/arrival time
ScheduledTime string `json:"ScheduledTime"`
// State indicates the current status of the departure (e.g., "InTime", "Delayed", "Cancelled")
State string `json:"State"`
// RouteChanges contains information about any route diversions or changes
RouteChanges []string `json:"RouteChanges"`
// Diva contains DVB-specific identifiers for the vehicle/line
Diva Diva `json:"Diva"`
// CancelReasons contains reasons if the departure is cancelled
CancelReasons []string `json:"CancelReasons"`
// Occupancy indicates how crowded the vehicle is (e.g., "Low", "Medium", "High")
Occupancy string `json:"Occupancy"`
}
Departure represents a single departure or arrival at a monitored stop. It contains detailed information about the vehicle, timing, and any disruptions.
type Direction ¶
type Direction struct {
// Name is the destination name for this direction (e.g., "Striesen", "Löbtau")
Name string `json:"Name"`
// TimeTables lists available timetables for this direction
TimeTables []TimeTable `json:"TimeTables"`
}
Direction represents a specific direction or destination for a public transport line. Each line typically has two directions (e.g., inbound and outbound).
type Diva ¶
type Diva struct {
// Number is the DIVA line number identifier.
// This is a standardized identifier used across the transport network
// for uniquely identifying transport lines.
Number string `json:"Number"`
// Network indicates which transport network this identifier belongs to.
// For Dresden, this is typically "vvo" (Verkehrsverbund Oberelbe),
// but may include other regional networks for connecting services.
Network string `json:"Network"`
}
Diva contains DVB-specific identifiers
type GetLinesParams ¶
type GetLinesParams struct {
// StopId is the unique identifier for the stop. This is required and cannot be empty.
// Use the GetPoint API to find stop IDs based on stop names or locations.
StopId string
// Format specifies the response format. Optional parameter.
// Supported values depend on the DVB API implementation.
Format *string
}
GetLinesParams contains the parameters for retrieving available public transport lines for a stop. This API provides information about which bus and tram lines serve a particular stop.
type GetLinesResponse ¶
type GetLinesResponse struct {
// Lines is an array of public transport lines that serve the specified stop
Lines []Line `json:"Lines"`
// Status contains the API response status including error codes and messages
Status Status `json:"Status"`
// ExpirationTime indicates when this response data expires and should be refreshed
ExpirationTime string `json:"ExpirationTime"`
}
GetLinesResponse represents the response from the DVB lines API. It contains information about all public transport lines that serve a specific stop.
type GetPointParams ¶
type GetPointParams struct {
// Query is the search term for finding a point. This is required and cannot be empty.
// Examples: "Hauptbahnhof", "Dresden Altstadt", "Neustadt Bahnhof"
Query string
// Format specifies the response format. Optional parameter.
// Supported values depend on the DVB API implementation.
Format *string
// StopsOnly when set to true, limits the search results to public transport stops only.
// When false or nil, includes other points of interest as well.
StopsOnly *bool
// AssignedStops when set to true, includes only stops that are assigned to specific lines.
// When false or nil, includes all matching stops regardless of line assignments.
AssignedStops *bool
// Limit restricts the maximum number of results returned.
// Must be a positive integer. If nil or 0, uses the API's default limit.
Limit *int
// Dvb when set to true, includes only DVB (Dresden public transport) stops.
// When false or nil, may include stops from other transport providers.
Dvb *bool
}
GetPointParams contains the parameters for finding a point/stop using the DVB point finder API. The point finder allows searching for public transport stops, stations, and points of interest.
type GetPointResponse ¶
type GetPointResponse struct {
// PointStatus indicates the status of the point search operation
PointStatus string `json:"PointStatus"`
// Status contains the API response status including error codes and messages
Status Status `json:"Status"`
// Points is an array of point identifiers that match the search query
Points []string `json:"Points"`
// ExpirationTime indicates when this response data expires and should be refreshed
ExpirationTime string `json:"ExpirationTime"`
}
GetPointResponse represents the response from the DVB point finder API. It contains information about the search results and status.
type GetRouteParams ¶
type GetRouteParams struct {
// Origin is the starting point for the journey. This is required and cannot be empty.
// Can be a stop ID (from GetPoint API) or a location name.
Origin string
// Destination is the end point for the journey. This is required and cannot be empty.
// Can be a stop ID (from GetPoint API) or a location name.
Destination string
// Format specifies the response format. Optional parameter.
// Supported values depend on the DVB API implementation.
Format *string
// IsArrivalTime when set to true, treats the Time parameter as arrival time.
// When false or nil, treats Time as departure time (default behavior).
IsArrivalTime *bool
// ShortTermChanges when set to true, includes short-term changes like delays or cancellations.
// When false or nil, uses scheduled times without real-time updates.
ShortTermChanges *bool
// Time specifies the departure or arrival time for the journey. Optional parameter.
// Format should be compatible with the DVB API time format.
// If not specified, uses the current time.
Time *string
// Via specifies an intermediate stop that the route should pass through.
// Optional parameter for more specific route planning.
Via *string
}
GetRouteParams contains the parameters for trip planning between two locations. This API provides journey planning with public transport connections, including walking routes, transfers, and timing information.
type GetRouteResponse ¶
type GetRouteResponse struct {
// SessionId is a unique identifier for this trip planning session
SessionId string `json:"SessionId"`
// Status contains the API response status including error codes and messages
Status Status `json:"Status"`
// Routes is an array of possible journey options from origin to destination
Routes []Route `json:"Routes"`
}
GetRouteResponse represents the response from the DVB trip planning API. It contains multiple route options with detailed journey information.
type Line ¶
type Line struct {
// Name is the display name of the line (e.g., "11", "85", "S1")
Name string `json:"Name"`
// Mot indicates the mode of transport (e.g., "Tram", "Bus", "S-Bahn")
Mot string `json:"Mot"`
// Changes contains information about any service changes or disruptions for this line
Changes []string `json:"Changes,omitempty"`
// Directions lists all directions this line travels from the current stop
Directions []Direction `json:"Directions"`
// Diva contains DVB-specific identifiers for the line
Diva Diva `json:"Diva"`
}
Line represents a single public transport line that serves a stop. It contains information about the line, its directions, and available timetables.
type MonitorStopParams ¶
type MonitorStopParams struct {
// StopId is the unique identifier for the stop to monitor. This is required and cannot be empty.
// Use the GetPoint API to find stop IDs based on stop names or locations.
StopId string
// Format specifies the response format. Optional parameter.
// Supported values depend on the DVB API implementation.
Format *string
// Time specifies the time for which to get departures. Optional parameter.
// Format should be compatible with the DVB API time format.
// If not specified, uses the current time.
Time *string
// IsArrival when set to true, shows arrivals instead of departures.
// When false or nil, shows departures (default behavior).
IsArrival *bool
// Limit restricts the maximum number of departures/arrivals returned.
// Must be a positive integer. If nil or 0, uses the API's default limit.
Limit *int
// ShortTermChanges when set to true, includes short-term changes like delays or cancellations.
// When false or nil, may not include the most recent real-time updates.
ShortTermChanges *bool
// MentzOnly when set to true, includes only data from the Mentz system.
// When false or nil, includes data from all available systems.
MentzOnly *bool
}
MonitorStopParams contains the parameters for monitoring departures from a specific stop. This is used to get real-time departure information for public transport vehicles.
type MonitorStopResponse ¶
type MonitorStopResponse struct {
// Name is the official name of the monitored stop
Name string `json:"Name"`
// Status contains the API response status including error codes and messages
Status Status `json:"Status"`
// Place indicates the city or area where the stop is located
Place string `json:"Place"`
// ExpirationTime indicates when this response data expires and should be refreshed
ExpirationTime string `json:"ExpirationTime"`
// Departures is an array of upcoming departures/arrivals from this stop
Departures []Departure `json:"Departures"`
}
MonitorStopResponse represents the response from the DVB stop monitoring API. It contains real-time departure/arrival information for a specific stop.
type Mot ¶
type Mot struct {
// DlId is the DVB line identifier
DlId *string `json:"DlId,omitempty"`
// StatelessId is an alternative identifier for the transport line
StatelessId *string `json:"StatelessId,omitempty"`
// Type indicates the mode of transport (e.g., "Tram", "Bus", "S-Bahn", "Walking")
Type string `json:"Type"`
// Name is the line name or number (e.g., "11", "85", "S1")
Name *string `json:"Name,omitempty"`
// Direction indicates the destination or direction of the vehicle
Direction *string `json:"Direction,omitempty"`
// Changes contains information about any service changes or disruptions
Changes []string `json:"Changes,omitempty"`
// Diva contains DVB-specific identifiers
Diva *Diva `json:"Diva,omitempty"`
// TransportationCompany is the name of the transport operator
TransportationCompany *string `json:"TransportationCompany,omitempty"`
// OperatorCode is the code identifying the transport operator
OperatorCode *string `json:"OperatorCode,omitempty"`
// ProductName describes the type of service (e.g., "Straßenbahn", "Stadtbus")
ProductName *string `json:"ProductName,omitempty"`
// TrainNumber is the specific train number for rail services
TrainNumber *string `json:"TrainNumber,omitempty"`
}
Mot represents detailed mode of transport information for a route segment. This contains more specific information than the summary in MotChain.
type MotChain ¶
type MotChain struct {
// DlId is the DVB line identifier
DlId string `json:"DlId"`
// StatelessId is an alternative identifier for the transport line
StatelessId string `json:"StatelessId"`
// Type indicates the mode of transport (e.g., "Tram", "Bus", "S-Bahn", "Walking")
Type string `json:"Type"`
// Name is the line name or number (e.g., "11", "85", "S1")
Name string `json:"Name"`
// Direction indicates the destination or direction of the vehicle
Direction string `json:"Direction"`
// Changes contains information about any service changes or disruptions
Changes []string `json:"Changes"`
// Diva contains DVB-specific identifiers
Diva Diva `json:"Diva"`
// TransportationCompany is the name of the transport operator
TransportationCompany string `json:"TransportationCompany"`
// OperatorCode is the code identifying the transport operator
OperatorCode string `json:"OperatorCode"`
// ProductName describes the type of service (e.g., "Straßenbahn", "Stadtbus")
ProductName string `json:"ProductName"`
// TrainNumber is the specific train number for rail services
TrainNumber string `json:"TrainNumber"`
}
MotChain represents a mode of transport used in the journey. This provides summary information about each transport line used.
type PartialRoute ¶
type PartialRoute struct {
// PartialRouteId is a unique identifier for this route segment
PartialRouteId *int `json:"PartialRouteId,omitempty"`
// Duration is the time required for this segment in minutes
Duration int `json:"Duration"`
// Mot contains detailed information about the mode of transport for this segment
Mot Mot `json:"Mot"`
// MapDataIndex points to the relevant map data for this segment
MapDataIndex *int `json:"MapDataIndex,omitempty"`
// Shift indicates any timing adjustments for this segment
Shift string `json:"Shift"`
// RegularStops lists all stops visited during this segment (for public transport)
RegularStops []RegularStop `json:"RegularStops,omitempty"`
// ChangeoverEndangered indicates if a transfer connection might be at risk
ChangeoverEndangered *bool `json:"ChangeoverEndangered,omitempty"`
// NextDepartureTimes lists alternative departure times for this segment
NextDepartureTimes []string `json:"NextDepartureTimes,omitempty"`
// PreviousDepartureTimes lists earlier departure options for this segment
PreviousDepartureTimes []string `json:"PreviousDepartureTimes,omitempty"`
}
PartialRoute represents a single segment of the overall journey. This could be a walking segment, a ride on public transport, or a transfer.
type Platform ¶
type Platform struct {
// Name is the display name or identifier of the platform.
// This could be a platform number (e.g., "1", "2A") for train stations,
// or a position identifier for bus/tram stops.
Name string `json:"Name"`
// Type indicates the kind of platform or stop.
// Examples include "Platform" for railway platforms,
// "Stop" for bus/tram stops, or other location-specific types.
Type string `json:"Type"`
}
Platform represents information about a physical platform or stop position where passengers board or alight from public transport vehicles.
type RegularStop ¶
type RegularStop struct {
// ArrivalTime is the scheduled arrival time at this stop
ArrivalTime string `json:"ArrivalTime"`
// DepartureTime is the scheduled departure time from this stop
DepartureTime string `json:"DepartureTime"`
// ArrivalRealTime is the real-time arrival time including delays
ArrivalRealTime *string `json:"ArrivalRealTime,omitempty"`
// DepartureRealTime is the real-time departure time including delays
DepartureRealTime *string `json:"DepartureRealTime,omitempty"`
// Place indicates the city or area where this stop is located
Place string `json:"Place"`
// Name is the official name of the stop
Name string `json:"Name"`
// Type indicates the type of stop (e.g., "Platform", "Stop")
Type string `json:"Type"`
// DataId is a unique identifier for this stop in the data system
DataId string `json:"DataId"`
// DhId is an alternative identifier for this stop
DhId string `json:"DhId"`
// Platform contains information about the platform or stop position
Platform Platform `json:"Platform"`
// Latitude is the geographical latitude coordinate of the stop
Latitude int `json:"Latitude"`
// Longitude is the geographical longitude coordinate of the stop
Longitude int `json:"Longitude"`
// DepartureState indicates the current status of departures from this stop
DepartureState *string `json:"DepartureState,omitempty"`
// ArrivalState indicates the current status of arrivals at this stop
ArrivalState *string `json:"ArrivalState,omitempty"`
// CancelReasons contains reasons if services at this stop are cancelled
CancelReasons []string `json:"CancelReasons"`
// ParkAndRail contains information about park and ride facilities
ParkAndRail []string `json:"ParkAndRail"`
// Occupancy indicates how crowded the vehicle is at this stop
Occupancy string `json:"Occupancy"`
}
RegularStop represents a stop visited during a journey segment. This provides detailed timing and location information for each stop.
type Route ¶
type Route struct {
// PriceLevel indicates the fare zone level for this route
PriceLevel int `json:"PriceLevel"`
// Price is the cost of a single ticket for this journey
Price string `json:"Price"`
// PriceDayTicket is the cost of a day ticket that covers this journey
PriceDayTicket string `json:"PriceDayTicket"`
// Net indicates the transport network (e.g., "VVO" for Dresden area)
Net string `json:"Net"`
// Duration is the total journey time in minutes
Duration int `json:"Duration"`
// Interchanges is the number of transfers required for this route
Interchanges int `json:"Interchanges"`
// MotChain lists all modes of transport used in this journey
MotChain []MotChain `json:"MotChain"`
// NumberOfFareZones indicates how many fare zones this journey crosses
NumberOfFareZones string `json:"NumberOfFareZones"`
// NumberOfFareZonesDayTicket indicates fare zones for day ticket pricing
NumberOfFareZonesDayTicket string `json:"NumberOfFareZonesDayTicket"`
// FareZoneNames lists the names of fare zones crossed during the journey
FareZoneNames string `json:"FareZoneNames"`
// FareZoneNamesDayTicket lists fare zone names for day ticket calculation
FareZoneNamesDayTicket string `json:"FareZoneNamesDayTicket"`
// FareZoneOrigin is the fare zone number of the starting point
FareZoneOrigin int `json:"FareZoneOrigin"`
// FareZoneDestination is the fare zone number of the destination
FareZoneDestination int `json:"FareZoneDestination"`
// RouteId is a unique identifier for this specific route
RouteId int `json:"RouteId"`
// PartialRoutes contains detailed step-by-step journey information
PartialRoutes []PartialRoute `json:"PartialRoutes"`
// MapData contains coordinate information for mapping the route
MapData []string `json:"MapData"`
// Tickets lists all available ticket types for this journey
Tickets []Ticket `json:"Tickets"`
}
Route represents a single journey option from origin to destination. It contains comprehensive information about the trip including timing, cost, and detailed steps.
type Status ¶
type Status struct {
// Code is the status code returned by the DVB API.
// Typical values include success codes and various error codes
// that indicate different types of failures or issues.
Code string `json:"Code"`
// Message provides human-readable information about the status.
// This field contains error descriptions when the request fails,
// or may be empty for successful requests.
Message string `json:"Message,omitempty"`
}
Status represents the response status from DVB API calls. It contains information about whether the request was successful and provides error details when applicable.
type Ticket ¶
type Ticket struct {
// Name is the display name of the ticket type
Name string `json:"Name"`
// PriceLevel indicates the fare zone level for this ticket
PriceLevel int `json:"PriceLevel"`
// Price is the cost of this ticket type
Price string `json:"Price"`
// NumberOfFareZones indicates how many fare zones this ticket covers
NumberOfFareZones string `json:"NumberOfFareZones"`
// FareZoneNames lists the names of fare zones covered by this ticket
FareZoneNames string `json:"FareZoneNames"`
}
Ticket represents a ticket option available for the journey. This includes pricing information for different ticket types.
type TimeTable ¶
type TimeTable struct {
// Id is the unique identifier for this timetable
Id string `json:"Id"`
// Name is the display name for this timetable (e.g., "Werktag", "Samstag")
Name string `json:"Name"`
}
TimeTable represents a specific timetable variant for a line direction. Different timetables may apply during different times or days.