util

package
v0.0.0-...-70af2fa Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeFeedMessage

func MakeFeedMessage(t time.Time) *gtfsrt.FeedMessage

MakeFeedMessage preapres a GTFS-RT FeedMessage object and adds a valid FeedHeader to it

func MakeTranslatedString

func MakeTranslatedString(s string) *gtfsrt.TranslatedString

MakeTranslatedString takes a string and warps it into a gtfs-realtime TranslatedString object

func MissingColumnCheck

func MissingColumnCheck(file string, required []string, row map[string]string) error

MissingColumnCheck returns nil if all required columns are set in the given row, returns an MissingColumn error otherwise

func StringSliceHas

func StringSliceHas(s sort.StringSlice, x string) bool

StringSliceHas checks if element is inside a StringSlice

func StringSliceInsert

func StringSliceInsert(s sort.StringSlice, x string) sort.StringSlice

StringSliceInsert adds x into sort.StringSlice

func ZipStrings

func ZipStrings(a []string, b []string) (zipped map[string]string)

ZipStrings maps elements from a to elements from b, such that a[i] in the returned map to b[i]

Types

type InvalidGtfsReference

type InvalidGtfsReference struct {
	ReferingFile       string
	Column             string
	Value              string
	ExpectedDefinition string
}

InvalidGtfsReference is an error object used when one GTFS file references an non-existant field

func (InvalidGtfsReference) Error

func (e InvalidGtfsReference) Error() string

type MissingColumn

type MissingColumn struct {
	File     string
	Required []string
	Missing  []string
}

MissingColumn is an error object used when a CSV file is missing a required column

func (MissingColumn) Error

func (e MissingColumn) Error() string

type RequestError

type RequestError struct {
	URL        string
	Status     string
	StatusCode int
}

RequestError is an error object used when a server responds with an unexpected return code

func (RequestError) Error

func (e RequestError) Error() string

type Resource

type Resource interface {
	Check() (bool, error)
	Fetch() (io.ReadCloser, error)
}

Resource interface represents an external, fetchable resource: Check() should check if the resource should be updated, Fetch() fetches the resource.

type ResourceHTTP

type ResourceHTTP struct {
	Client          *http.Client
	URL             string
	Checktime       time.Time
	Peroid          time.Duration
	FetchedETag     string
	FetchedModified time.Time
}

ResourceHTTP is a Resource located on the internet, fetchable via HTTP/HTTPS

func (*ResourceHTTP) Check

func (r *ResourceHTTP) Check() (fetch bool, err error)

Check checks if the file on the internet has changed, but only if more then r.Peroid has passed since r.Fetchtime

func (*ResourceHTTP) Fetch

func (r *ResourceHTTP) Fetch() (io.ReadCloser, error)

Fetch returns the ReadCloser with access to the underlaying file

type ResourceLocal

type ResourceLocal struct {
	Path            string
	Checktime       time.Time
	Peroid          time.Duration
	FetchedModified time.Time
}

ResourceLocal is a Resource located on the file system

func (*ResourceLocal) Check

func (r *ResourceLocal) Check() (fetch bool, err error)

Check checks if the file has changed, but only if more then r.Peroid has passed since r.Fetchtime

func (*ResourceLocal) Fetch

func (r *ResourceLocal) Fetch() (io.ReadCloser, error)

Fetch returns the ReadCloser with access to the underlaying file

type UnexpectedHost

type UnexpectedHost struct {
	Where    string
	Host     string
	Expected string
}

UnexpectedHost is an error object used when a link points to an invalid host

func (UnexpectedHost) Error

func (e UnexpectedHost) Error() string

Jump to

Keyboard shortcuts

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