frostfs-node/pkg/innerring/locode.go
Alex Vanin 20de74a505 Rename package name
Due to source code relocation from GitHub.

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
2023-03-07 16:38:26 +03:00

53 lines
1.3 KiB
Go

package innerring
import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap"
irlocode "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap/nodevalidation/locode"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode"
locodedb "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode/db"
locodebolt "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode/db/boltdb"
"github.com/spf13/viper"
)
func (s *Server) newLocodeValidator(cfg *viper.Viper) (netmap.NodeValidator, error) {
locodeDB := locodebolt.New(locodebolt.Prm{
Path: cfg.GetString("locode.db.path"),
},
locodebolt.ReadOnly(),
)
s.registerStarter(locodeDB.Open)
s.registerIOCloser(locodeDB)
return irlocode.New(irlocode.Prm{
DB: (*locodeBoltDBWrapper)(locodeDB),
}), nil
}
type locodeBoltEntryWrapper struct {
*locodedb.Key
*locodedb.Record
}
func (l *locodeBoltEntryWrapper) LocationName() string {
return l.Record.LocationName()
}
type locodeBoltDBWrapper locodebolt.DB
func (l *locodeBoltDBWrapper) Get(lc *locode.LOCODE) (irlocode.Record, error) {
key, err := locodedb.NewKey(*lc)
if err != nil {
return nil, err
}
rec, err := (*locodebolt.DB)(l).Get(*key)
if err != nil {
return nil, err
}
return &locodeBoltEntryWrapper{
Key: key,
Record: rec,
}, nil
}