forked from digisan/id-mgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.go
70 lines (55 loc) · 1.29 KB
/
load.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package idmgr
import (
"fmt"
"os"
"strconv"
"strings"
. "github.com/digisan/go-generics"
fd "github.com/digisan/gotk/file-dir"
. "github.com/digisan/id-mgr/id"
)
// FILL 1._segs, 2._masks,3.mAlias 4.mRecord & REDO BuildHierarchy
func IngestTree(fPath string) error {
var (
i int
err error
)
// can report NOT EXISTING error if id-tree.txt doesn't exist
if _, err = os.ReadFile(fPath); err != nil {
return err
}
// *** clearing all ID which includes clearing their aliases
if err := ClrAllID(); err != nil {
return err
}
_, e := fd.FileLineScan(fPath, func(line string) (bool, string) {
i++
if i == 1 {
err = Init64bitsFromStr(line)
return false, ""
}
// id | aliases
if strings.Count(line, "|") != 1 {
err = fmt.Errorf("ingested fail: incorrect ID format @%v", line)
return false, ""
}
ln := strings.TrimSpace(line)
id_alias := strings.Split(ln, "|")
// *** ID *** //
id, e := strconv.ParseUint(id_alias[0], 16, 64) // id in dump file is hex
if e != nil {
err = fmt.Errorf("ingested fail: id parsed error @%w", e)
return false, ""
}
// *** Alias *** //
_, err = SetID(ID(id), TypesAsAnyToAnys(strings.Split(id_alias[1], "^"))...)
return true, ""
}, "")
if e != nil {
return e
}
if err != nil {
return err
}
return nil
}