forked from TrueCloudLab/frostfs-node
cdd1274e1c
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>
31 lines
890 B
Go
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[:])
|
|
}
|