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
|
|
|
// LocationCode represents a location 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 LocationCode locodecolumn.LocationCode
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// LocationCodeFromString parses a string UN/LOCODE location code
|
|
|
|
// and returns a LocationCode.
|
2021-02-08 17:27:19 +00:00
|
|
|
func LocationCodeFromString(s string) (*LocationCode, error) {
|
|
|
|
lc, err := locodecolumn.LocationCodeFromString(s)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not parse location code: %w", err)
|
2021-02-08 17:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return LocationFromColumn(lc)
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// LocationFromColumn converts a UN/LOCODE country code to a LocationCode.
|
2021-02-08 17:27:19 +00:00
|
|
|
func LocationFromColumn(cc *locodecolumn.LocationCode) (*LocationCode, error) {
|
|
|
|
return (*LocationCode)(cc), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LocationCode) String() string {
|
|
|
|
syms := (*locodecolumn.LocationCode)(l).Symbols()
|
|
|
|
return string(syms[:])
|
|
|
|
}
|