2021-02-08 17:27:19 +00:00
|
|
|
package locodedb
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-02-08 17:27:19 +00:00
|
|
|
locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column"
|
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// CountryCode represents a country code for
|
|
|
|
// the storage in the NeoFS location database.
|
2021-02-08 17:27:19 +00:00
|
|
|
type CountryCode locodecolumn.CountryCode
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// CountryCodeFromString parses a string UN/LOCODE country code
|
|
|
|
// and returns a CountryCode.
|
2021-02-08 17:27:19 +00:00
|
|
|
func CountryCodeFromString(s string) (*CountryCode, error) {
|
|
|
|
cc, err := locodecolumn.CountryCodeFromString(s)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not parse country code: %w", err)
|
2021-02-08 17:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CountryFromColumn(cc)
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// CountryFromColumn converts a UN/LOCODE country code to a CountryCode.
|
2021-02-08 17:27:19 +00:00
|
|
|
func CountryFromColumn(cc *locodecolumn.CountryCode) (*CountryCode, error) {
|
|
|
|
return (*CountryCode)(cc), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CountryCode) String() string {
|
|
|
|
syms := (*locodecolumn.CountryCode)(c).Symbols()
|
|
|
|
return string(syms[:])
|
|
|
|
}
|