tt

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 17 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckColor

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

CheckColor returns an error if the value is not a valid hex color

func CheckCurrency

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

CheckCurrency returns an error if the value is not a known currency

func CheckEmail

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

CheckEmail returns an error if the value is not a reasonably valid email address

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 CheckLanguage

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

CheckLanguage returns an error if the value is not a known language

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 CheckTimezone

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

CheckTimezone returns an error if the value is not a known timezone

func CheckURL

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

CheckURL returns an error if the value is not a reasonably valid url

func FromCsv added in v0.16.0

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 SecondsToString

func SecondsToString(secs int) string

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

func StringToSeconds

func StringToSeconds(value string) (int, error)

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

func ToCsv added in v0.16.0

func ToCsv(val any) (string, error)

ToCsv converts any value to a CSV string representation

func TryCsv added in v0.16.0

func TryCsv(val any) string

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

Types

type Bool added in v0.12.0

type Bool struct {
	Val   bool
	Valid bool
}

func NewBool added in v0.12.0

func NewBool(v bool) Bool

func (Bool) MarshalGQL added in v0.12.0

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

func (Bool) MarshalJSON added in v0.12.0

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

func (*Bool) Scan added in v0.12.0

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

func (Bool) String added in v0.12.0

func (r Bool) String() string

func (*Bool) UnmarshalGQL added in v0.12.0

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

func (*Bool) UnmarshalJSON added in v0.12.0

func (r *Bool) UnmarshalJSON(v []byte) error

func (Bool) Value added in v0.12.0

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

type Counts added in v0.14.0

type Counts map[string]int

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

func (Counts) MarshalGQL added in v0.14.0

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

func (*Counts) Scan added in v0.14.0

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

func (*Counts) UnmarshalGQL added in v0.14.0

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

func (Counts) Value added in v0.14.0

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

type CurrencyAmount added in v0.13.0

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

func NewCurrencyAmount added in v0.13.0

func NewCurrencyAmount(v float64) CurrencyAmount

func (*CurrencyAmount) SetCurrency added in v0.13.0

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

func (CurrencyAmount) ToCsv added in v0.13.0

func (r CurrencyAmount) ToCsv() string

type Date

type Date struct {
	Val   time.Time
	Valid bool
}

Date is a nullable date

func NewDate

func NewDate(v time.Time) Date

func ParseDate added in v0.12.0

func ParseDate(s string) (Date, error)

func (Date) After added in v0.12.0

func (r Date) After(other Date) bool

func (Date) Before added in v0.12.0

func (r Date) Before(other Date) bool

func (Date) IsZero

func (r Date) IsZero() bool

func (Date) MarshalGQL

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

func (Date) MarshalJSON

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

func (*Date) Scan

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

func (Date) String

func (r Date) String() string

func (*Date) UnmarshalGQL

func (r *Date) UnmarshalGQL(src interface{}) error

func (*Date) UnmarshalJSON

func (r *Date) UnmarshalJSON(v []byte) error

func (Date) Value

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

type Float

type Float struct {
	Val   float64
	Valid bool
}

Float is a nullable float64

func NewFloat

func NewFloat(v float64) Float

func (Float) MarshalGQL

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

func (Float) MarshalJSON

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

func (*Float) Scan

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

func (Float) String

func (r Float) String() string

func (*Float) UnmarshalGQL

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

func (*Float) UnmarshalJSON

func (r *Float) UnmarshalJSON(v []byte) error

func (Float) Value

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

type Geometry

type Geometry struct {
	Valid    bool
	Geometry geom.T
}

Geometry is an EWKB/GeoJSON wrapper for arbitary geometry.

func (Geometry) MarshalGQL

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

func (Geometry) MarshalJSON

func (g Geometry) MarshalJSON() ([]byte, error)

func (*Geometry) Scan

func (g *Geometry) Scan(src interface{}) error

func (Geometry) String

func (g Geometry) String() string

String returns the GeoJSON representation

func (*Geometry) UnmarshalGQL

func (g *Geometry) UnmarshalGQL(v interface{}) error

func (Geometry) Value

func (g Geometry) 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) Int added in v0.13.0

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) UnmarshalGQL

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

type Ints

type Ints struct {
	Valid bool
	Val   []int
}

Ints is a nullable slice of []int

func NewInts

func NewInts(v []int) Ints

func (*Ints) Scan

func (a *Ints) Scan(value interface{}) error

func (Ints) Value

func (a Ints) Value() (driver.Value, error)

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) UnmarshalGQL

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

type LineString

type LineString struct {
	Valid bool
	geom.LineString
}

LineString is an EWKB/SL encoded LineString

func NewLineStringFromFlatCoords

func NewLineStringFromFlatCoords(coords []float64) LineString

NewLineStringFromFlatCoords returns a new LineString from flat (3) coordinates

func (LineString) MarshalGQL

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

func (LineString) MarshalJSON

func (g LineString) MarshalJSON() ([]byte, error)

func (*LineString) Scan

func (g *LineString) Scan(src interface{}) error

func (LineString) String

func (g LineString) String() string

func (*LineString) UnmarshalGQL

func (g *LineString) UnmarshalGQL(v interface{}) error

func (LineString) Value

func (g LineString) Value() (driver.Value, error)

type Map added in v0.16.0

type Map struct {
	Valid bool
	Val   map[string]any
}

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

func NewMap added in v0.16.0

func NewMap(val map[string]any) Map

func (Map) MarshalGQL added in v0.16.0

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

func (Map) MarshalJSON added in v0.16.0

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

func (*Map) Scan added in v0.16.0

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

func (*Map) UnmarshalGQL added in v0.16.0

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

func (*Map) UnmarshalJSON added in v0.16.0

func (r *Map) UnmarshalJSON(v []byte) error

func (Map) Value added in v0.16.0

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

type Option added in v0.13.0

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

func (*Option[T]) Error added in v0.13.0

func (r *Option[T]) Error() error

func (Option[T]) MarshalJSON added in v0.13.0

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

func (*Option[T]) Present added in v0.13.0

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

func (Option[T]) Ptr added in v0.16.0

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

func (*Option[T]) Scan added in v0.13.0

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

func (Option[T]) String added in v0.13.0

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

func (*Option[T]) UnmarshalJSON added in v0.13.0

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

func (Option[T]) Value added in v0.13.0

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

type Point

type Point struct {
	Valid bool
	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 (g Point) MarshalGQL(w io.Writer)

func (Point) MarshalJSON

func (g Point) MarshalJSON() ([]byte, error)

func (*Point) Scan

func (g *Point) Scan(src interface{}) error

func (Point) String

func (g Point) String() string

func (*Point) UnmarshalGQL

func (g *Point) UnmarshalGQL(v interface{}) error

func (Point) Value

func (g Point) Value() (driver.Value, error)

type Polygon

type Polygon struct {
	Valid bool
	geom.Polygon
}

Polygon is an EWKB/SL encoded Polygon

func (Polygon) MarshalGQL

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

func (Polygon) MarshalJSON

func (g Polygon) MarshalJSON() ([]byte, error)

func (*Polygon) Scan

func (g *Polygon) Scan(src interface{}) error

func (Polygon) String

func (g Polygon) String() string

func (*Polygon) UnmarshalGQL

func (g *Polygon) UnmarshalGQL(v interface{}) error

func (Polygon) Value

func (g Polygon) Value() (driver.Value, error)

type RouteType

type RouteType struct {
	Code     int
	Name     string
	Category string
	Parent   int
}

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 String

type String struct {
	Option[string]
}

func NewString

func NewString(v string) String

func (String) MarshalGQL

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

func (*String) UnmarshalGQL

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

type Strings

type Strings []String

Strings helps read and write []String as JSON

func NewStrings added in v0.16.0

func NewStrings(v []string) Strings

func (Strings) MarshalGQL added in v0.12.0

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

func (Strings) MarshalJSON added in v0.12.0

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

func (*Strings) Scan

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

func (*Strings) UnmarshalGQL added in v0.12.0

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

func (*Strings) UnmarshalJSON added in v0.12.0

func (r *Strings) UnmarshalJSON(v []byte) error

func (Strings) Value

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

type Tags

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

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) MarshalJSON

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

func (*Tags) Scan

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

func (*Tags) Set

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

Set a tag value

func (*Tags) UnmarshalGQL

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

func (*Tags) UnmarshalJSON

func (r *Tags) UnmarshalJSON(v []byte) error

func (Tags) Value

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

type Time

type Time struct {
	Val   time.Time
	Valid bool
}

Time is a nullable date without time component

func NewTime

func NewTime(v time.Time) Time

func (Time) IsZero

func (r Time) IsZero() bool

IsZero returns if this is a zero value.

func (Time) MarshalGQL

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

func (Time) MarshalJSON

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

func (*Time) Scan

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

func (Time) String

func (r Time) String() string

func (*Time) UnmarshalGQL

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

func (*Time) UnmarshalJSON added in v0.12.0

func (r *Time) UnmarshalJSON(v []byte) error

func (Time) Value

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

type WideTime

type WideTime struct {
	Seconds int
	Valid   bool
}

WideTime handles seconds since midnight, allows >24 hours.

func NewWideTime

func NewWideTime(value string) (wt WideTime, err error)

NewWideTime converts the csv string to a WideTime.

func NewWideTimeFromSeconds

func NewWideTimeFromSeconds(value int) WideTime

NewWideTimeFromSeconds creates a valid WideTime from Seconds.

func (*WideTime) FromCsv added in v0.13.0

func (wt *WideTime) FromCsv(v string) error

func (WideTime) MarshalGQL

func (wt WideTime) MarshalGQL(w io.Writer)

func (*WideTime) Scan

func (wt *WideTime) Scan(src interface{}) error

func (WideTime) String

func (wt WideTime) String() string

func (WideTime) ToCsv added in v0.13.0

func (wt WideTime) ToCsv() string

func (*WideTime) UnmarshalGQL

func (wt *WideTime) UnmarshalGQL(v interface{}) error

func (WideTime) Value

func (wt WideTime) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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