2021-02-08 17:27:19 +00:00
|
|
|
package locodedb
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
locodecolumn "github.com/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
|
|
|
|
// the storage in the NeoFS 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[:])
|
|
|
|
}
|