tt

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: GPL-3.0 Imports: 22 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendIf

func AppendIf(err error, field string, errs []error) []error

func CheckConditionallyRequired

func CheckConditionallyRequired(field string, value string) (errs []error)

CheckPresent returns an error if a string is empty

func CheckErrors

func CheckErrors(ent any) []error

func CheckInArray

func CheckInArray(field string, value string, values ...string) []error

CheckInArray returns an error if the value is not in the set of provided values.

func CheckInArrayInt

func CheckInArrayInt[T int | int64](field string, value T, values ...T) []error

CheckInArrayInt returns an error if the value is not in the set of provided values.

func CheckInsideRange

func CheckInsideRange(field string, value float64, min float64, max float64) (errs []error)

CheckInsideRange returns an error if the value is outside of the specified range

func CheckInsideRangeInt

func CheckInsideRangeInt[T int | int64](field string, value T, min T, max T) (errs []error)

CheckInsideRangeInt returns an error if the value is outside of the specified range

func CheckPositive

func CheckPositive(field string, value float64) (errs []error)

CheckPositive returns an error if the value is non-negative

func CheckPositiveInt

func CheckPositiveInt[T int | int64](field string, value T) (errs []error)

CheckPositiveInt returns an error if the value is non-negative

func CheckPresent

func CheckPresent(field string, value string) (errs []error)

CheckPresent returns an error if a string is empty

func CheckWarnings

func CheckWarnings(ent any) []error

func FallbackDate

func FallbackDate(currentTime time.Time, startTime time.Time, endTime time.Time, fallbackWeek time.Time) (time.Time, bool, error)

FallbackDate gets an equivalent day-of-week within fallbackWeek if currentTime is not with startTime/endTime bounds

func FirstError

func FirstError(errs ...error) error

func FromCsv

func FromCsv(val any, strv string) error

FromCSV sets the field from a CSV representation of the value.

func IsValidColor

func IsValidColor(color string) bool

IsValidColor check is valid color

func IsValidCurrency

func IsValidCurrency(value string) bool

IsValidCurrency check is valid currency

func IsValidEmail

func IsValidEmail(email string) bool

IsValidEmail check if valid email

func IsValidLanguage

func IsValidLanguage(value string) bool

IsValidLang check is valid language

func IsValidTimezone

func IsValidTimezone(value string) (string, bool)

IsValidTimezone check is valid timezone

func IsValidURL

func IsValidURL(url string) bool

IsValidURL check is valid url

func ReflectCheckErrors

func ReflectCheckErrors(ent any) []error

Error wrapping helpers

func ReflectUpdateKeys

func ReflectUpdateKeys(emap *EntityMap, ent any) []error

func RelativeDate

func RelativeDate(currentTime time.Time, relativeDateLabel string) (time.Time, error)

RelativeDate gets a date reltive to the provided time; currentTime should have timezone set.

func SecondsToString

func SecondsToString(secs int64) string

SecondsToString takes seconds-since-midnight and returns a GTFS-style time.

func StringToSeconds

func StringToSeconds(value string) (int64, error)

StringToSeconds parses a GTFS-style time and returns seconds since midnight.

func ToCsv

func ToCsv(val any) (string, error)

ToCsv converts any value to a CSV string representation

func TryCsv

func TryCsv(val any) string

TryCsv converts any value to a CSV string representation, ignoring errors

func TrySetField

func TrySetField(err error, field string) error

Types

type Bool

type Bool struct {
	Option[bool]
}

func NewBool

func NewBool(v bool) Bool

func (Bool) MarshalGQL

func (r Bool) MarshalGQL(w io.Writer)

func (*Bool) UnmarshalGQL

func (r *Bool) UnmarshalGQL(v any) error

type CanReflectCheck

type CanReflectCheck interface {
	String() string
	IsPresent() bool
	Check() error
}

type Clock

type Clock interface {
	Now() time.Time
}

Allow for time mocking

type Color

type Color struct {
	Option[string]
}

func NewColor

func NewColor(v string) Color

func (Color) Check

func (r Color) Check() error

func (Color) MarshalGQL

func (r Color) MarshalGQL(w io.Writer)

func (*Color) UnmarshalGQL

func (r *Color) UnmarshalGQL(v any) error

type Counts

type Counts map[string]int

Counts is a simple map[string]int with json support

func (Counts) MarshalGQL

func (r Counts) MarshalGQL(w io.Writer)

func (*Counts) Scan

func (r *Counts) Scan(value interface{}) error

func (*Counts) UnmarshalGQL

func (r *Counts) UnmarshalGQL(v interface{}) error

func (Counts) Value

func (r Counts) Value() (driver.Value, error)

type Currency

type Currency struct {
	Option[string]
}

func NewCurrency

func NewCurrency(v string) Currency

func (Currency) Check

func (r Currency) Check() error

type CurrencyAmount

type CurrencyAmount struct {
	Option[float64]
	// contains filtered or unexported fields
}

func NewCurrencyAmount

func NewCurrencyAmount(v float64) CurrencyAmount

func (*CurrencyAmount) SetCurrency

func (r *CurrencyAmount) SetCurrency(value string) error

func (CurrencyAmount) ToCsv

func (r CurrencyAmount) ToCsv() string

type DatabaseEntity

type DatabaseEntity struct {
	ID int `csv:"-"`
}

func (DatabaseEntity) GetID

func (ent DatabaseEntity) GetID() int

GetID returns the integer ID.

func (*DatabaseEntity) SetID

func (ent *DatabaseEntity) SetID(id int)

SetID sets the integer ID.

type Date

type Date struct {
	Option[time.Time]
}

Date is a nullable date

func NewDate

func NewDate(v time.Time) Date

func ParseDate

func ParseDate(s string) (Date, error)

func (Date) After

func (r Date) After(other Date) bool

func (Date) Before

func (r Date) Before(other Date) bool

func (Date) MarshalGQL

func (r Date) MarshalGQL(w io.Writer)

func (Date) MarshalJSON

func (r Date) MarshalJSON() ([]byte, error)

func (Date) String

func (r Date) String() string

func (Date) ToCsv

func (r Date) ToCsv() string

func (*Date) UnmarshalGQL

func (r *Date) UnmarshalGQL(v any) error

type Email

type Email struct {
	Option[string]
}

func NewEmail

func NewEmail(v string) Email

func (Email) Check

func (r Email) Check() error

func (Email) MarshalGQL

func (r Email) MarshalGQL(w io.Writer)

func (*Email) UnmarshalGQL

func (r *Email) UnmarshalGQL(v any) error

type Entity

type Entity interface {
	EntityID() string
	Filename() string
}

Entity provides an interface for GTFS entities.

type EntityMap

type EntityMap struct {
	// contains filtered or unexported fields
}

EntityMap stores correspondances between Entity IDs, e.g. StopID -> Stop's integer ID in a database.

func NewEntityMap

func NewEntityMap() *EntityMap

NewEntityMap returns a new EntityMap.

func (*EntityMap) Get

func (emap *EntityMap) Get(efn string, eid string) (string, bool)

Get gets directly by filename, eid

func (*EntityMap) GetEntity

func (emap *EntityMap) GetEntity(ent Entity) (string, bool)

GetEntity returns the new ID for an Entity.

func (*EntityMap) KeysFor

func (emap *EntityMap) KeysFor(efn string) []string

KeysFor returns the keys for a filename.

func (*EntityMap) Set

func (emap *EntityMap) Set(efn string, oldid string, newid string) error

Set directly adds an entry to the set.

func (*EntityMap) SetEntity

func (emap *EntityMap) SetEntity(ent Entity, oldid string, newid string) error

SetEntity sets the old and new ID for an Entity.

func (*EntityMap) Update

func (emap *EntityMap) Update(other EntityMap)

Update copies values from another EntityMap.

func (*EntityMap) UpdateKey

func (emap *EntityMap) UpdateKey(v canSet, efn string) error

type EntityWithConditionalErrors

type EntityWithConditionalErrors interface {
	ConditionalErrors() []error
}

type EntityWithErrors

type EntityWithErrors interface {
	Errors() []error
}

type EntityWithExtra

type EntityWithExtra interface {
	SetExtra(string, string)
	GetExtra(string) (string, bool)
	ClearExtra()
	ExtraKeys() []string
}

type EntityWithID

type EntityWithID interface {
	GetID() int
}

type EntityWithLoadErrors

type EntityWithLoadErrors interface {
	LoadErrors() []error
	LoadWarnings() []error
	AddError(error)
	AddWarning(error)
}

type EntityWithReferences

type EntityWithReferences interface {
	UpdateKeys(*EntityMap) error
}

type EntityWithWarnings

type EntityWithWarnings interface {
	Warnings() []error
}

type ErrorEntity

type ErrorEntity struct {
	// contains filtered or unexported fields
}

func (*ErrorEntity) AddError

func (ent *ErrorEntity) AddError(err error)

AddError adds a loading error to the entity, e.g. from a CSV parse failure

func (*ErrorEntity) AddWarning

func (ent *ErrorEntity) AddWarning(err error)

AddWarning .

func (*ErrorEntity) LoadErrors

func (ent *ErrorEntity) LoadErrors() []error

func (*ErrorEntity) LoadWarnings

func (ent *ErrorEntity) LoadWarnings() []error

type ExtraEntity

type ExtraEntity struct {
	// contains filtered or unexported fields
}

func (*ExtraEntity) ClearExtra

func (ent *ExtraEntity) ClearExtra()

func (*ExtraEntity) ExtraKeys

func (ent *ExtraEntity) ExtraKeys() []string

func (*ExtraEntity) GetExtra

func (ent *ExtraEntity) GetExtra(key string) (string, bool)

func (*ExtraEntity) SetExtra

func (ent *ExtraEntity) SetExtra(key string, value string)

SetExtra adds a string key, value pair to the entity's extra fields.

type FeedVersionEntity

type FeedVersionEntity struct {
	FeedVersionID int `csv:"-"`
}

func (*FeedVersionEntity) GetFeedVersionID

func (ent *FeedVersionEntity) GetFeedVersionID() int

GetFeedVersionID returns the Entity's FeedVersionID.

func (*FeedVersionEntity) SetFeedVersionID

func (ent *FeedVersionEntity) SetFeedVersionID(fvid int)

SetFeedVersionID sets the Entity's FeedVersionID.

type Float

type Float struct {
	Option[float64]
}

Float is a nullable float64

func NewFloat

func NewFloat(v float64) Float

func (Float) Float

func (r Float) Float() float64

func (Float) MarshalGQL

func (r Float) MarshalGQL(w io.Writer)

func (Float) String

func (r Float) String() string

func (*Float) UnmarshalGQL

func (r *Float) UnmarshalGQL(v any) error

type Geometry

type Geometry struct {
	GeometryOption[geom.T]
}

func NewGeometry

func NewGeometry(v geom.T) Geometry

func (Geometry) MarshalGQL

func (r Geometry) MarshalGQL(w io.Writer)

func (*Geometry) UnmarshalGQL

func (r *Geometry) UnmarshalGQL(v any) error

type GeometryOption

type GeometryOption[T geom.T] struct {
	Val   T
	Valid bool
}

Point is an EWKB/SL encoded point

func NewGeometryOption

func NewGeometryOption[T geom.T](v T) GeometryOption[T]

func (GeometryOption[T]) FlatCoords

func (g GeometryOption[T]) FlatCoords() []float64

func (GeometryOption[T]) MarshalJSON

func (g GeometryOption[T]) MarshalJSON() ([]byte, error)

func (*GeometryOption[T]) Scan

func (g *GeometryOption[T]) Scan(src interface{}) error

func (GeometryOption[T]) Stride

func (g GeometryOption[T]) Stride() int

func (*GeometryOption[T]) UnmarshalJSON

func (g *GeometryOption[T]) UnmarshalJSON(data []byte) error

func (GeometryOption[T]) Value

func (g GeometryOption[T]) Value() (driver.Value, error)

type Int

type Int struct {
	Option[int64]
}

Int is a nullable int

func NewInt

func NewInt(v int) Int

func (Int) Float

func (r Int) Float() float64

func (Int) Int

func (r Int) Int() int

Int is a convenience function for int(v)

func (Int) MarshalGQL

func (r Int) MarshalGQL(w io.Writer)

func (*Int) SetInt

func (r *Int) SetInt(v int)

func (*Int) UnmarshalGQL

func (r *Int) UnmarshalGQL(v any) error

type Ints

type Ints struct {
	Option[[]int64]
}

Ints is a nullable slice of []int

func NewInts

func NewInts(v []int) Ints

type Key

type Key struct {
	Option[string]
}

Key is a nullable foreign key constraint, similar to sql.NullString

func NewKey

func NewKey(v string) Key

func (Key) Int

func (r Key) Int() int

func (Key) IsPresent

func (r Key) IsPresent() bool

func (*Key) SetInt

func (r *Key) SetInt(v int)

type Language

type Language struct {
	Option[string]
}

func NewLanguage

func NewLanguage(v string) Language

func (Language) Check

func (r Language) Check() error

func (Language) MarshalGQL

func (r Language) MarshalGQL(w io.Writer)

func (*Language) UnmarshalGQL

func (r *Language) UnmarshalGQL(v any) error

type LineEntity

type LineEntity struct {
	// contains filtered or unexported fields
}

func (LineEntity) Line

func (ent LineEntity) Line() int

func (*LineEntity) SetLine

func (ent *LineEntity) SetLine(line int)

type LineString

type LineString struct {
	GeometryOption[*geom.LineString]
}

LineString is an EWKB/SL encoded LineString

func NewLineString

func NewLineString(v *geom.LineString) LineString

func NewLineStringFromFlatCoords

func NewLineStringFromFlatCoords(coords []float64) LineString

NewLineStringFromFlatCoords returns a new LineString from flat (3) coordinates

func (LineString) MarshalGQL

func (r LineString) MarshalGQL(w io.Writer)

func (LineString) ToLineM

func (g LineString) ToLineM() tlxy.LineM

func (LineString) ToPoints

func (g LineString) ToPoints() []tlxy.Point

func (*LineString) UnmarshalGQL

func (r *LineString) UnmarshalGQL(v any) error

type Map

type Map struct {
	Option[map[string]any]
}

Map helps read and write map[string]any as JSON

func NewMap

func NewMap(val map[string]any) Map

func (Map) MarshalGQL

func (r Map) MarshalGQL(w io.Writer)

func (*Map) UnmarshalGQL

func (r *Map) UnmarshalGQL(v any) error

func (Map) Value

func (r Map) Value() (driver.Value, error)

type MinEntity

type MinEntity struct {
}

MinEntity provides minimum set of default methods.

func (MinEntity) EntityID

func (ent MinEntity) EntityID() string

EntityID returns the entity ID.

func (MinEntity) Filename

func (ent MinEntity) Filename() string

Filename returns the filename for this entity.

type MockClock

type MockClock struct {
	T time.Time
}

A mock clock with a fixed time

func (MockClock) Now

func (dc MockClock) Now() time.Time

type Option

type Option[T any] struct {
	Val   T
	Valid bool
}

func NewOption

func NewOption[T any](v T) Option[T]

func (Option[T]) Check

func (r Option[T]) Check() error

func (Option[T]) IsPresent

func (r Option[T]) IsPresent() bool

func (Option[T]) IsValid

func (r Option[T]) IsValid() bool

func (*Option[T]) IsZero

func (r *Option[T]) IsZero() bool

func (Option[T]) MarshalJSON

func (r Option[T]) MarshalJSON() ([]byte, error)

func (*Option[T]) OrSet

func (r *Option[T]) OrSet(v T)

func (Option[T]) Ptr

func (r Option[T]) Ptr() *T

func (*Option[T]) Scan

func (r *Option[T]) Scan(src interface{}) error

func (*Option[T]) Set

func (r *Option[T]) Set(v T)

func (Option[T]) String

func (r Option[T]) String() string

func (*Option[T]) UnmarshalJSON

func (r *Option[T]) UnmarshalJSON(v []byte) error

func (*Option[T]) Unset

func (r *Option[T]) Unset()

func (Option[T]) Value

func (r Option[T]) Value() (driver.Value, error)

type Point

type Point struct {
	GeometryOption[*geom.Point]
}

Point is an EWKB/SL encoded point

func NewPoint

func NewPoint(lon, lat float64) Point

NewPoint returns a Point from lon, lat

func (Point) MarshalGQL

func (r Point) MarshalGQL(w io.Writer)

func (*Point) ToPoint

func (g *Point) ToPoint() tlxy.Point

func (*Point) UnmarshalGQL

func (r *Point) UnmarshalGQL(v any) error

func (*Point) X

func (g *Point) X() float64

func (*Point) Y

func (g *Point) Y() float64

type Polygon

type Polygon struct {
	GeometryOption[*geom.Polygon]
}

Polygon is an EWKB/SL encoded Polygon

func NewPolygon

func NewPolygon(v *geom.Polygon) Polygon

func (Polygon) MarshalGQL

func (r Polygon) MarshalGQL(w io.Writer)

func (*Polygon) UnmarshalGQL

func (r *Polygon) UnmarshalGQL(v any) error

type RealClock

type RealClock struct{}

Real system clock

func (RealClock) Now

func (dc RealClock) Now() time.Time

type RouteType

type RouteType struct {
	Code     int    `json:"code"`
	Name     string `json:"name"`
	Category string `json:"category"`
	Parent   int    `json:"parent"`
}

RouteType contains details on each possible route_type

func GetBasicRouteType

func GetBasicRouteType(code int) (RouteType, bool)

GetBasicRouteType returns the closest approximate basic route_type for an extended route_type.

func GetRouteType

func GetRouteType(code int) (RouteType, bool)

GetRouteType returns the details for a given route_type value.

type Seconds

type Seconds struct {
	Option[int64]
}

func NewSeconds

func NewSeconds(s int) Seconds

func NewSecondsFromString

func NewSecondsFromString(s string) (Seconds, error)

func (Seconds) HMS

func (r Seconds) HMS() (int, int, int)

func (Seconds) Int

func (r Seconds) Int() int

func (Seconds) MarshalGQL

func (r Seconds) MarshalGQL(w io.Writer)

func (Seconds) MarshalJSON

func (r Seconds) MarshalJSON() ([]byte, error)

func (*Seconds) Scan

func (r *Seconds) Scan(src interface{}) error

func (*Seconds) SetInt

func (r *Seconds) SetInt(v int)

func (Seconds) String

func (r Seconds) String() string

func (Seconds) ToCsv

func (r Seconds) ToCsv() string

func (*Seconds) UnmarshalGQL

func (r *Seconds) UnmarshalGQL(v any) error

func (*Seconds) UnmarshalJSON

func (r *Seconds) UnmarshalJSON(d []byte) error

type String

type String struct {
	Option[string]
}

func NewString

func NewString(v string) String

func (String) Int

func (r String) Int() int

func (String) IsPresent

func (r String) IsPresent() bool

func (String) MarshalGQL

func (r String) MarshalGQL(w io.Writer)

func (String) String

func (r String) String() string

func (*String) UnmarshalGQL

func (r *String) UnmarshalGQL(v any) error

type Strings

type Strings struct {
	Option[[]string]
}

Strings helps read and write []String as JSON

func NewStrings

func NewStrings(v []string) Strings

func (Strings) MarshalGQL

func (r Strings) MarshalGQL(w io.Writer)

func (*Strings) UnmarshalGQL

func (r *Strings) UnmarshalGQL(v any) error

type Tags

type Tags struct {
	Option[map[string]string]
}

Tags is a map[string]string with json and gql marshal support. This is a struct instead of bare map[string]string because of a gqlgen issue.

func (Tags) Get

func (r Tags) Get(k string) (string, bool)

Get a tag value by key

func (Tags) Keys

func (r Tags) Keys() []string

Keys return the tag keys

func (Tags) MarshalGQL

func (r Tags) MarshalGQL(w io.Writer)

func (*Tags) Set

func (r *Tags) Set(k, v string)

Set a tag value

func (*Tags) UnmarshalGQL

func (r *Tags) UnmarshalGQL(v any) error

type Time

type Time struct {
	Option[time.Time]
}

Time is a nullable date without time component

func NewTime

func NewTime(v time.Time) Time

func (Time) MarshalGQL

func (r Time) MarshalGQL(w io.Writer)

func (*Time) UnmarshalGQL

func (r *Time) UnmarshalGQL(v any) error

type Timestamps

type Timestamps struct {
	CreatedAt time.Time `csv:"-"`
	UpdatedAt time.Time `csv:"-"`
}

Timestamps .

func (*Timestamps) UpdateTimestamps

func (ent *Timestamps) UpdateTimestamps()

UpdateTimestamps initializes or updates CreatedAt / UpdatedAt

type Timezone

type Timezone struct {
	Option[string]
}

func NewTimezone

func NewTimezone(v string) Timezone

func (Timezone) Check

func (r Timezone) Check() error

func (Timezone) MarshalGQL

func (r Timezone) MarshalGQL(w io.Writer)

func (*Timezone) UnmarshalGQL

func (r *Timezone) UnmarshalGQL(v any) error

type Url

type Url struct {
	Option[string]
}

func NewUrl

func NewUrl(v string) Url

func (Url) Check

func (r Url) Check() error

func (Url) MarshalGQL

func (r Url) MarshalGQL(w io.Writer)

func (*Url) UnmarshalGQL

func (r *Url) UnmarshalGQL(v any) error

Jump to

Keyboard shortcuts

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