2021-02-08 17:27:19 +00:00
|
|
|
package locodedb
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
locodecolumn "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode/column"
|
2021-02-08 17:27:19 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// CountryCode represents a country code for
|
2023-02-05 15:59:38 +00:00
|
|
|
// the storage in the FrostFS 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[:])
|
|
|
|
}
|