airportsdb

package
v0.37.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is a descriptor of the OpenFlights database in csv format.

For correct operation, DB must be created using the constructor (New) based on the required parameters and optional components. After successful creation, The DB is immediately ready to work through API.

func New

func New(prm Prm, opts ...Option) *DB

New creates a new instance of the DB.

Panics if at least one value of the parameters is invalid.

The created DB does not require additional initialization and is completely ready for work.

func (*DB) CountryName

func (db *DB) CountryName(code *locodedb.CountryCode) (name string, err error)

CountryName scans the records of the OpenFlights Country table to an in-memory table (once), and returns the name of the country by code.

Returns locodedb.ErrCountryNotFound if no entry matches.

func (*DB) Get

func (db *DB) Get(locodeRecord locode.Record) (*locodedb.AirportRecord, error)

Get scans the records of the OpenFlights Airport to an in-memory table (once), and returns an entry that matches the passed UN/LOCODE record.

Records are matched if they have the same country code and either same IATA code or same city name (location name in UN/LOCODE).

Returns locodedb.ErrAirportNotFound if no entry matches.

type Option

type Option func(*options)

Option sets an optional parameter of DB.

type Prm

type Prm struct {
	// Path to OpenFlights Airport csv table.
	//
	// Must not be empty.
	AirportsPath string

	// Path to OpenFlights Countries csv table.
	//
	// Must not be empty.
	CountriesPath string
}

Prm groups the required parameters of the DB's constructor.

All values must comply with the requirements imposed on them. Passing incorrect parameter values will result in constructor failure (error or panic depending on the implementation).

Jump to

Keyboard shortcuts

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