geofox

package module
v0.0.4-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 12 Imported by: 0

README

geofox-go

Go Report Card

About

geofox-go is a Go client for the Geofox Thin Interface (GTI) to provide information about Hamburg's public transport system.

Install

go get -u github.com/kristoffn/geofox-go

Example usage

This small application is an example client to send an init request to the Geofox API.

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/kristoffn/geofox-go"
)

func main() {
	username := os.Getenv("GEOFOX_USER")
	password := os.Getenv("GEOFOX_PASSWD")
	client, err := geofox.New(username, password)
	if err != nil {
		panic(err)
	}

	initResponse, err := client.Init(context.Background())
	if err != nil {
		panic(err)
	}
	fmt.Printf("%+v", initResponse)
}

Example output:

&{ReturnCode:OK BeginOfService:15.01.2023 EndOfService:10.12.2023 ID:1.0.733 DataID:33.93.02 BuildDate:18.01.2023 BuildTime:14:36:21 BuildText:Regelfahrplan 2022}

Note

❗ This library is still in a very experimental state and subject to potential breaking changes. Use at your own discretion.

Documentation

Index

Constants

View Source
const (
	LangEnglish = "en"
	LangGerman  = "de"
)
View Source
const (
	AuthTypeHmacSHA1 = "HmacSHA1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Username string
	Password string
	AuthType string
	BaseURL  string
	// contains filtered or unexported fields
}

func New

func New(username, password string, opts ...Option) (*API, error)

func (*API) Init

func (a *API) Init(ctx context.Context) (*InitResponse, error)

func (*API) ListLines

func (a *API) ListLines(ctx context.Context, modTypes []ModificationType, withSublines bool) (*LLResponse, error)

func (*API) ListStations

func (a *API) ListStations(ctx context.Context, modTypes []ModificationType, coordType CoordinateType) (*LSResponse, error)

type APIResponse

type APIResponse struct {
	Body       []byte
	StatusCode int
	Headers    http.Header
}

type BaseRequest

type BaseRequest struct {
	Language   string `json:"language,omitempty"`
	Version    int32  `json:"version,omitempty"`
	FilterType Filter `json:"filterType,omitempty"`
}

type CoordinateType

type CoordinateType string
const (
	EPSG4326  CoordinateType = "EPSG_4326"
	EPSG31466 CoordinateType = "EPSG_31466"
	EPSG31467 CoordinateType = "EPSG_31467"
	EPSG31468 CoordinateType = "EPSG_31468"
	EPSG31469 CoordinateType = "EPSG_31469"
)

type Coordniate

type Coordniate struct {
	X    float64        `json:"x"`
	Y    float64        `json:"y"`
	Type CoordinateType `json:"type"`
}

type ErrorForbidden

type ErrorForbidden struct {
	StatusCode int
	ReturnCode GeofoxReturnCode
}

func (*ErrorForbidden) Error

func (e *ErrorForbidden) Error() string

type ErrorGeneric

type ErrorGeneric struct {
	StatusCode int
	ReturnCode GeofoxReturnCode
}

func (*ErrorGeneric) Error

func (e *ErrorGeneric) Error() string

type ErrorInternalServerError

type ErrorInternalServerError struct {
	StatusCode int
	ReturnCode GeofoxReturnCode
}

func (*ErrorInternalServerError) Error

func (e *ErrorInternalServerError) Error() string

type ErrorNotFound

type ErrorNotFound struct {
	StatusCode int
	ReturnCode GeofoxReturnCode
}

func (*ErrorNotFound) Error

func (e *ErrorNotFound) Error() string

type ErrorTooManyRequests

type ErrorTooManyRequests struct {
	StatusCode int
	ReturnCode GeofoxReturnCode
}

func (*ErrorTooManyRequests) Error

func (e *ErrorTooManyRequests) Error() string

type ErrorUnauthorized

type ErrorUnauthorized struct {
	StatusCode int
	ReturnCode GeofoxReturnCode
}

func (*ErrorUnauthorized) Error

func (e *ErrorUnauthorized) Error() string

type Filter

type Filter string
const (
	NoFilter        Filter = "NO_FILTER"
	FilterHVVListed Filter = "HVV_LISTED"
)

type GeofoxError

type GeofoxError interface {
	Error() string
}

type GeofoxReturnCode

type GeofoxReturnCode string
const (
	RCOK                GeofoxReturnCode = "OK"
	RCCNTooMany         GeofoxReturnCode = "ERROR_CN_TOO_MANY"
	RCCommError         GeofoxReturnCode = "ERROR_COMM"
	RCRouteError        GeofoxReturnCode = "ERROR_ROUTE"
	RCErrorText         GeofoxReturnCode = "ERROR_TEXT"
	RCStartDestTooClose GeofoxReturnCode = "START_DEST_TOO_CLOSE"
)

type InitRequest

type InitRequest struct {
	BaseRequest
}

type InitResponse

type InitResponse struct {
	ReturnCode     string `json:"returnCode"`
	BeginOfService string `json:"beginOfService"`
	EndOfService   string `json:"endOfService"`
	ID             string `json:"id"`
	DataID         string `json:"dataId"`
	BuildDate      string `json:"buildDate"`
	BuildTime      string `json:"buildTime"`
	BuildText      string `json:"buildText"`
}

type LLRequest

type LLRequest struct {
	BaseRequest
	WithSublines      bool               `json:"withSublines"`
	DataReleaseID     string             `json:"dataReleaseID"`
	ModificationTypes []ModificationType `json:"modificationTypes"`
}

type LLResponse

type LLResponse struct {
	ReturnCode    GeofoxReturnCode `json:"returnCode"`
	ErrorText     string           `json:"errorText"`
	ErrorDevInfo  string           `json:"errorDevInfo"`
	DataReleaseID string           `json:"dataReleaseID"`
	Lines         []LineListEntry  `json:"lines"`
}

type LSRequest

type LSRequest struct {
	BaseRequest
	DataReleaseID     string             `json:"dataReleaseID"`
	ModificationTypes []ModificationType `json:"modificationTypes"`
	CoordinateType    CoordinateType     `json:"coordinateType,omitempty"`
	FilterEquivalent  bool               `json:"filterEquivalent,omitempty"`
}

type LSResponse

type LSResponse struct {
	DataReleaseID string             `json:"dataReleaseID,omitempty"`
	Stations      []StationListEntry `json:"stations,omitempty"`
}

type Language

type Language string

type LineListEntry

type LineListEntry struct {
	ID               string             `json:"id"`
	Name             string             `json:"name"`
	CarrierNameShort string             `json:"carrierNameShort"`
	CarrierNameLong  string             `json:"carrierNameLong"`
	Sublines         []SublineListEntry `json:"sublines"`
	Exists           bool               `json:"exists"`
	Type             ServiceType        `json:"type"`
}

type ModificationType

type ModificationType string
const (
	ModTypeMain     ModificationType = "MAIN"
	ModTypePosition ModificationType = "POSITION"
	ModTypeSequence ModificationType = "SEQUENCE"
)

type Option

type Option func(*API) error

func Debug

func Debug() Option

type ServiceType

type ServiceType struct {
	SimpleType SimpleType `json:"simpleType"`
	ShortInfo  string     `json:"shortInfo"`
	LongInfo   string     `json:"longInfo"`
	Model      string     `json:"model"`
}

type SimpleType

type SimpleType string
const (
	STBus                SimpleType = "BUS"
	STTrain              SimpleType = "TRAIN"
	STShip               SimpleType = "SHIP"
	STFootpath           SimpleType = "FOOTPATH"
	STBicycle            SimpleType = "BICYCLE"
	STAirplane           SimpleType = "AIRPLANE"
	STChange             SimpleType = "CHANGE"
	STChangeSamePlatform SimpleType = "CHANGE_SAME_PLATFORM"
)

type StationLight

type StationLight struct {
	ID   string `json:"id"`
	Name string `json:"json"`
}

type StationListEntry

type StationListEntry struct {
	ID           string        `json:"id"`
	Name         string        `json:"name"`
	City         string        `json:"city"`
	CombinedName string        `json:"combinedName"`
	Shortcuts    []string      `json:"shortcuts"`
	Aliasses     []string      `json:"aliasses"`
	VehicleTypes []VehicleType `json:"vehicleTypes"`
	Coordniate   Coordniate    `json:"coordinate"`
	Exists       bool          `json:"exists"`
}

type SublineListEntry

type SublineListEntry struct {
	SublineNumber   string         `json:"sublineNumber"`
	VehicleType     VehicleType    `json:"vehicleType"`
	StationSequence []StationLight `json:"stationSequence"`
}

type VehicleType

type VehicleType string
const (
	VTypeRegionalBus  VehicleType = "REGIONALBUS"
	VTypeMetroBus     VehicleType = "METROBUS"
	VTypeNachtBus     VehicleType = "NACHTBUS"
	VTypeSchnellBus   VehicleType = "SCHNELLBUS"
	VTypeXpressBus    VehicleType = "XPRESSBUS"
	VTypeAST          VehicleType = "AST"
	VTypeSchiff       VehicleType = "SCHIFF"
	VTypeUBahn        VehicleType = "U_BAHN"
	VTypeSBahn        VehicleType = "S_BAHN"
	VTypeABahn        VehicleType = "A_BAHN"
	VTypeRegionalbahn VehicleType = "R_BAHN"
	VTypeFernbahn     VehicleType = "F_BAHN"
	VTypeEILBus       VehicleType = "EILBUS"
)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL