forked from TrueCloudLab/frostfs-locode-db
[#21] locode: Introduce locode overriding
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
16ff77e35c
commit
f2113a9c02
4 changed files with 71 additions and 4 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"io/fs"
|
||||
"sync"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode"
|
||||
)
|
||||
|
||||
// Prm groups the required parameters of the Table's constructor.
|
||||
|
@ -21,6 +23,11 @@ type Prm struct {
|
|||
//
|
||||
// Must not be empty.
|
||||
SubDivPath string
|
||||
|
||||
// Path to a csv table with UN/LOCODE overrides.
|
||||
//
|
||||
// Optional.
|
||||
OverridesPath string
|
||||
}
|
||||
|
||||
// Table is a descriptor of the UN/LOCODE table in csv format.
|
||||
|
@ -39,6 +46,8 @@ type Table struct {
|
|||
subDivOnce sync.Once
|
||||
|
||||
mSubDiv map[subDivKey]subDivRecord
|
||||
|
||||
overrides map[locode.LOCODE]locode.Record
|
||||
}
|
||||
|
||||
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
|
||||
|
@ -67,9 +76,15 @@ func New(prm Prm, opts ...Option) *Table {
|
|||
opts[i](o)
|
||||
}
|
||||
|
||||
return &Table{
|
||||
t := &Table{
|
||||
paths: append(o.extraPaths, prm.Path),
|
||||
mode: o.mode,
|
||||
subDivPath: prm.SubDivPath,
|
||||
}
|
||||
|
||||
if err := t.initOverrides(prm.OverridesPath); err != nil {
|
||||
panic(fmt.Errorf("init overrides: %w", err))
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue