vehicle

package
v0.0.0-...-161b4be Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchVehicle = errors.New("no such vehicle")
)

Exported errors.

Functions

func DisabledAsString

func DisabledAsString(status bool) string

DisabledAsString returns a stringified version of the Disabled field.

func HashAsKey

func HashAsKey(hash uint64) string

HashAsKey converts the given hash value into a string that can be used as key in the vehicle store.

func PrettyBrandName

func PrettyBrandName(brand string) string

PrettyBrandName titles-cases the given brand name unless its length is 3 or below, in which case everything is uppercased. This should handle most cases.

func PrettyFuelType

func PrettyFuelType(ft string) string

PrettyFuelType normalizes fuel-type by capitalizing the first letter only.

Types

type List

type List map[uint64]Vehicle

List contains vehicles that were found during parsing.

type LogEntry

type LogEntry struct {
	LoggedAt time.Time
	Message  string
}

LogEntry contains two parts: a timestamp (logging time) and a message.

func (LogEntry) String

func (log LogEntry) String() string

String displays a human readable log message.

func (*LogEntry) Unmarshal

func (log *LogEntry) Unmarshal(str string) error

Unmarshal takes a string containing exactly one colon and populates the LogEntry with a timestamp parsed from the first value (before the colon), and an unparsed message (after the colon).

type Meta

type Meta struct {
	Hash        uint64
	Source      string
	Country     RegCountry
	Ident       uint64
	LastUpdated time.Time
	Disabled    bool
}

Meta contains metadata for each vehicle.

type Query

type Query struct {
	Limit    int64
	Type     string
	Brand    string
	Model    string
	FuelType string
}

Query contains the search- and filter options for performing a query against the store.

type RegCountry

type RegCountry int

RegCountry represents a country of registration for a vehicle.

const (
	DK RegCountry = iota
	NO
)

List of allowed registration countries.

func RegCountryFromString

func RegCountryFromString(reg string) RegCountry

RegCountryFromString takes a string and returns the matching country of registration.

func (RegCountry) String

func (reg RegCountry) String() string

String returns the string representation of the RegCountry.

type Store

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

Store represents a Redis-compatible memory store such as Redis or Google Memory Store.

func NewStore

func NewStore(storeCnf config.MemStoreConfig, syncCnf config.SyncConfig, logger io.Writer) *Store

NewStore returns a new Store, which you can then interact with in order to start sync operations etc.

func (*Store) Clear

func (vs *Store) Clear() error

Clear clears out the entire vehicle store, including indexes but not the sync history.

func (*Store) Close

func (vs *Store) Close() error

Close disconnects from the memory store.

func (*Store) CountLog

func (vs *Store) CountLog() (int, error)

CountLog returns the number of log entries.

func (*Store) Disable

func (vs *Store) Disable(hash string) error

Disable disables the vehicle with the given hash value, if it exists.

func (*Store) Enable

func (vs *Store) Enable(hash string) error

Enable enables the vehicle with the given hash value, if it exists.

func (*Store) GetLastSynced

func (vs *Store) GetLastSynced() (string, error)

GetLastSynced returns the filename of the last file that was synchronised with the vehicle store. It returns an empty string if there is no filename.

func (*Store) LastLog

func (vs *Store) LastLog() (LogEntry, error)

LastLog returns the message that was last logged in the history.

func (*Store) Log

func (vs *Store) Log(msg string) error

Log logs a message to the vehicle store history together with the logging time.

func (*Store) LookupByHash

func (vs *Store) LookupByHash(hash string) (Vehicle, error)

LookupByHash performs a vehicle lookup by hash value, without side effects. Ie. it doesn't attempt to clear any indexes if no vehicle was found.

func (*Store) LookupByRegNr

func (vs *Store) LookupByRegNr(rc RegCountry, regNr string, showDisabled bool) (Vehicle, error)

LookupByRegNr attempts to lookup a vehicle by its registration number.

func (*Store) LookupByVIN

func (vs *Store) LookupByVIN(rc RegCountry, VIN string, showDisabled bool) (Vehicle, error)

LookupByVIN attempts to lookup a vehicle by its VIN number.

func (*Store) NewSyncOp

func (vs *Store) NewSyncOp(source string) SyncOpID

NewSyncOp starts a new synchronization operation and returns its id. Use this id for any further interactions with the operation. Note that his function is not thread-safe.

func (*Store) Open

func (vs *Store) Open() error

Open connects to the vehicle store.

func (*Store) QueryTo

func (vs *Store) QueryTo(w io.Writer, q Query) error

QueryTo performs a query/search agsinst the store and streams the results to the provided reader.

func (*Store) SetLastSynced

func (vs *Store) SetLastSynced(fname string) error

SetLastSynced replaces the logged filename of the file that was last synchronised with the vehicle store.

func (*Store) Status

func (vs *Store) Status(id SyncOpID) string

Status returns a status for the sync operation with the given id.

func (*Store) Sync

func (vs *Store) Sync(id SyncOpID, vehicles <-chan Vehicle, done <-chan bool) error

Sync reads from channel "vehicles" and synchronizes each one with the store. It stops when receiving a bool on channel "done". Along the way, it keeps track of the number of vehicles that were processed and synchronized. This data is stored on the syncOp.

func (*Store) SyncVehicle

func (vs *Store) SyncVehicle(veh Vehicle) (bool, error)

SyncVehicle synchronizes a single Vehicle with the memory store. It returns a bool indicating whether the vehicle was added/updated or not.

type SyncOpID

type SyncOpID int

SyncOpID is an integer reference to a running synchronization operation.

type Type

type Type int

Type represents the overall type of vehicle, ie. car, trailer, van etc.

const (
	Unknown Type = iota
	Car
	Bus
	Van
	Truck
	Trailer
)

List of supported vehicle types.

func TypeFromString

func TypeFromString(str string) Type

TypeFromString returns the Type that matches the given string (case insensitive match). If TypeFromString does not find a direct match, Type.Unknown is returned.

func (Type) String

func (t Type) String() string

String returns the string representation of the vehicle type.

type Vehicle

type Vehicle struct {
	MetaData     Meta `hash:"ignore"`
	Type         Type
	RegNr        string
	VIN          string
	Brand        string
	Model        string
	FuelType     string
	Variant      string
	FirstRegDate time.Time
}

Vehicle contains the core vehicle data that Autobot manages. As vehicles are persisted in Redis / Google Memory Store, they should not contain pointers.

func (Vehicle) FlexString

func (v Vehicle) FlexString(lb, leftPad string) string

FlexString returns a stringified multi-line representation of the Vehicle data structure.

func (*Vehicle) GenHash

func (v *Vehicle) GenHash() error

GenHash generates a unique hash value of the vehicle. The hash is stored in the vehicle metadata.

func (*Vehicle) Marshal

func (v *Vehicle) Marshal() (string, error)

Marshal converts the given Vehicle to a string using JSON encoding.

func (Vehicle) Slice

func (v Vehicle) Slice() [10]string

Slice returns most properties from Vehicle as a slice of strings, intended for use in CSV conversions.

func (Vehicle) String

func (v Vehicle) String() string

String returns a stringified representation of the Vehicle data structure.

func (*Vehicle) Unmarshal

func (v *Vehicle) Unmarshal(str string) error

Unmarshal converts the given string to a Vehicle using JSON decoding.

Jump to

Keyboard shortcuts

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