Documentation
¶
Index ¶
- Constants
- Variables
- func ErrInvalidFormat(field, expected string) error
- func ErrInvalidValue(field string, value interface{}) error
- func ErrMissingField(field string) error
- type APIError
- type Cache
- type Client
- func (c *Client) GetArrivals(ctx context.Context, req StationBoardRequest) ([]models.Departure, error)
- func (c *Client) GetArrivalsRaw(ctx context.Context, req StationBoardRequest) (json.RawMessage, error)
- func (c *Client) GetDepartures(ctx context.Context, req StationBoardRequest) ([]models.Departure, error)
- func (c *Client) GetDeparturesRaw(ctx context.Context, req StationBoardRequest) (json.RawMessage, error)
- func (c *Client) GetFormation(ctx context.Context, req FormationRequest) (*models.Formation, error)
- func (c *Client) GetFormationRaw(ctx context.Context, req FormationRequest) (json.RawMessage, error)
- func (c *Client) GetJourney(ctx context.Context, journeyID string, withPolyline bool) (*models.Journey, error)
- func (c *Client) GetJourneyRaw(ctx context.Context, journeyID string, withPolyline bool) (json.RawMessage, error)
- func (c *Client) SearchLocations(ctx context.Context, query string) ([]models.Location, error)
- func (c *Client) SearchLocationsRaw(ctx context.Context, query string) (json.RawMessage, error)
- func (c *Client) SearchNearby(ctx context.Context, req NearbyRequest) ([]models.Location, error)
- func (c *Client) SearchNearbyRaw(ctx context.Context, req NearbyRequest) (json.RawMessage, error)
- func (c *Client) Timezone() *time.Location
- type ClientOption
- type DepartureRequest
- type FormationRequest
- type NearbyRequest
- type StationBoardRequest
- type ValidationError
Constants ¶
const ( // BaseURL is the base URL for the bahn.de API BaseURL = "https://www.bahn.de/web/api" // EndpointDepartures returns departures at a station // Required params: datum, zeit, ortExtId, ortId, mitVias, maxVias, verkehrsmittel[] EndpointDepartures = "/reiseloesung/abfahrten" // EndpointArrivals returns arrivals at a station // Required params: datum, zeit, ortExtId, ortId, mitVias, maxVias, verkehrsmittel[] EndpointArrivals = "/reiseloesung/ankuenfte" // EndpointLocations searches for stations by name // Required params: suchbegriff, typ, limit EndpointLocations = "/reiseloesung/orte" // EndpointNearby searches for stations by coordinates // Required params: lat, long, radius, maxNo EndpointNearby = "/reiseloesung/orte/nearby" // EndpointJourney returns journey/trip details // Required params: journeyId, poly EndpointJourney = "/reiseloesung/fahrt" // EndpointFormation returns train carriage formation // Required params: administrationId, category, date, evaNumber, number, time EndpointFormation = "/reisebegleitung/wagenreihung/vehicle-sequence" )
Variables ¶
var ( // ErrNotFound indicates the requested resource was not found ErrNotFound = errors.New("not found") // ErrInvalidRequest indicates the request parameters are invalid ErrInvalidRequest = errors.New("invalid request") // ErrServerError indicates a server-side error ErrServerError = errors.New("server error") // ErrTimeout indicates the request timed out ErrTimeout = errors.New("request timed out") // ErrNoResults indicates no results were found ErrNoResults = errors.New("no results found") )
Common errors
var ModesOfTransit = []string{
"ICE",
"EC_IC",
"IR",
"REGIONAL",
"SBAHN",
"BUS",
"SCHIFF",
"UBAHN",
"TRAM",
"ANRUFPFLICHTIG",
}
ModesOfTransit contains all supported transport modes
Functions ¶
func ErrInvalidFormat ¶
func ErrInvalidValue ¶
Types ¶
type APIError ¶
APIError represents an error returned by the bahn.de API
func NewAPIError ¶
NewAPIError creates a new API error
func NewAPIErrorWithMessage ¶
NewAPIErrorWithMessage creates a new API error with a custom message
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the API client for bahn.de
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient creates a new API client
func (*Client) GetArrivals ¶
func (c *Client) GetArrivals(ctx context.Context, req StationBoardRequest) ([]models.Departure, error)
GetArrivals fetches arrivals for a station
func (*Client) GetArrivalsRaw ¶
func (c *Client) GetArrivalsRaw(ctx context.Context, req StationBoardRequest) (json.RawMessage, error)
GetArrivalsRaw fetches arrivals and returns raw JSON
func (*Client) GetDepartures ¶
func (c *Client) GetDepartures(ctx context.Context, req StationBoardRequest) ([]models.Departure, error)
GetDepartures fetches departures for a station
func (*Client) GetDeparturesRaw ¶
func (c *Client) GetDeparturesRaw(ctx context.Context, req StationBoardRequest) (json.RawMessage, error)
GetDeparturesRaw fetches departures and returns raw JSON
func (*Client) GetFormation ¶
GetFormation fetches train formation/composition data
func (*Client) GetFormationRaw ¶
func (c *Client) GetFormationRaw(ctx context.Context, req FormationRequest) (json.RawMessage, error)
GetFormationRaw fetches train formation data and returns raw JSON
func (*Client) GetJourney ¶
func (c *Client) GetJourney(ctx context.Context, journeyID string, withPolyline bool) (*models.Journey, error)
GetJourney fetches journey details by journey ID
func (*Client) GetJourneyRaw ¶
func (c *Client) GetJourneyRaw(ctx context.Context, journeyID string, withPolyline bool) (json.RawMessage, error)
GetJourneyRaw fetches journey details and returns raw JSON
func (*Client) SearchLocations ¶
SearchLocations searches for stations by name
func (*Client) SearchLocationsRaw ¶
SearchLocationsRaw searches for stations and returns raw JSON
func (*Client) SearchNearby ¶
SearchNearby searches for stations near a location
func (*Client) SearchNearbyRaw ¶
func (c *Client) SearchNearbyRaw(ctx context.Context, req NearbyRequest) (json.RawMessage, error)
SearchNearbyRaw searches for nearby stations and returns raw JSON
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures the Client
func WithCache ¶
func WithCache(cache Cache) ClientOption
WithCache enables caching with the provided cache implementation
func WithDefaultCache ¶
func WithDefaultCache() ClientOption
WithDefaultCache enables caching with the default file cache
func WithHTTPClient ¶
func WithHTTPClient(hc *http.Client) ClientOption
WithHTTPClient sets a custom HTTP client
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the HTTP client timeout
type DepartureRequest ¶
type DepartureRequest = StationBoardRequest
DepartureRequest is an alias for StationBoardRequest for backward compatibility
type FormationRequest ¶
type FormationRequest struct {
EVA int64 // Station EVA number
TrainType string // Train type (e.g., "ICE")
TrainNumber string // Train number (e.g., "623")
Departure time.Time // Departure time
}
FormationRequest contains parameters for a formation query
type NearbyRequest ¶
type NearbyRequest struct {
Latitude float64 // Latitude (required)
Longitude float64 // Longitude (required)
Radius int // Search radius in meters (default: 9999)
MaxNo int // Maximum number of results (default: 100)
}
NearbyRequest contains parameters for a nearby search
type StationBoardRequest ¶
type StationBoardRequest struct {
EVA int64 // Station EVA number (required)
StationID string // Station ID (required)
DateTime time.Time // Query time (defaults to now)
NumVias int // Number of via stations (default: 5)
ModesOfTransit []string // Filter by transport mode (default: all)
}
StationBoardRequest contains parameters for a departure/arrival query
type ValidationError ¶
ValidationError represents a validation error for request parameters
func NewValidationError ¶
func NewValidationError(field, message string) *ValidationError
NewValidationError creates a new validation error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string