1 files changed,
1 insertions(+),
14 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2025-05-01 21:06:41 +0300
Parent:
1a0c16f
M
parser/parser.go
··· 2 2 3 3 import ( 4 4 "errors" 5 - "maps" 6 5 7 6 "gopkg.in/yaml.v3" 8 7 ) ··· 13 12 Tags []string `yaml:"tags"` 14 13 Fields map[string]string `yaml:"fields"` 15 14 Notes []Note `yaml:"notes"` 16 - 17 - // fieldLookUp internal reserve mapping of [Fields] 18 - fieldLookUp map[string]string 19 15 } 20 16 21 17 func (d *DeckImport) FieldLookUp(field string) string { 22 18 // TODO: use ok notation here 23 19 24 - val := d.fieldLookUp[field] 20 + val := d.Fields[field] 25 21 return val 26 22 } 27 23 ··· 29 25 return nil 30 26 } 31 27 32 -func (d *DeckImport) buildLookUpTable() { 33 - d.fieldLookUp = make(map[string]string) 34 - maps.Copy(d.Fields, d.fieldLookUp) 35 -} 36 - 37 28 type Note struct { 38 29 Fields map[string]string 39 30 Tags []string ··· 66 57 func Parse(inp []byte) ([]DeckImport, error) { 67 58 var listRes []DeckImport 68 59 if err := yaml.Unmarshal(inp, &listRes); err == nil { 69 - for i := range listRes { 70 - listRes[i].buildLookUpTable() 71 - } 72 60 return listRes, nil 73 61 } 74 62 75 63 var single DeckImport 76 64 if err := yaml.Unmarshal(inp, &single); err == nil { 77 - single.buildLookUpTable() 78 65 return []DeckImport{single}, nil 79 66 } 80 67