frostfs-node/pkg/util/locode/db/country.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
870 B
Go

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