forked from TrueCloudLab/frostfs-node
[#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>
This commit is contained in:
parent
0be35859ed
commit
cdd1274e1c
6 changed files with 523 additions and 0 deletions
31
pkg/util/locode/db/location.go
Normal file
31
pkg/util/locode/db/location.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package locodedb
|
||||
|
||||
import (
|
||||
locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// LocationCode represents location code for
|
||||
// storage in the NeoFS location database.
|
||||
type LocationCode locodecolumn.LocationCode
|
||||
|
||||
// LocationCodeFromString parses string UN/LOCODE location code
|
||||
// and returns LocationCode.
|
||||
func LocationCodeFromString(s string) (*LocationCode, error) {
|
||||
lc, err := locodecolumn.LocationCodeFromString(s)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse location code")
|
||||
}
|
||||
|
||||
return LocationFromColumn(lc)
|
||||
}
|
||||
|
||||
// LocationFromColumn converts UN/LOCODE country code to LocationCode.
|
||||
func LocationFromColumn(cc *locodecolumn.LocationCode) (*LocationCode, error) {
|
||||
return (*LocationCode)(cc), nil
|
||||
}
|
||||
|
||||
func (l *LocationCode) String() string {
|
||||
syms := (*locodecolumn.LocationCode)(l).Symbols()
|
||||
return string(syms[:])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue