frostfs-node/pkg/util/locode/db/location.go
Leonard Lyubich cdd1274e1c [#316] locode: Define the API of location database
Define structure of keys and records of the location database. Define the
interfaces of all components necessary for the formation of the database.
Implement the function of filling the database.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-02-09 11:05:55 +03:00

31 lines
890 B
Go

package locodedb
import (
locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column"
"github.com/pkg/errors"
)
// LocationCode represents location code for
// storage in the NeoFS location database.
type LocationCode locodecolumn.LocationCode
// LocationCodeFromString parses string UN/LOCODE location code
// and returns LocationCode.
func LocationCodeFromString(s string) (*LocationCode, error) {
lc, err := locodecolumn.LocationCodeFromString(s)
if err != nil {
return nil, errors.Wrap(err, "could not parse location code")
}
return LocationFromColumn(lc)
}
// LocationFromColumn converts UN/LOCODE country code to LocationCode.
func LocationFromColumn(cc *locodecolumn.LocationCode) (*LocationCode, error) {
return (*LocationCode)(cc), nil
}
func (l *LocationCode) String() string {
syms := (*locodecolumn.LocationCode)(l).Symbols()
return string(syms[:])
}