-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaml.go
709 lines (606 loc) · 20 KB
/
yaml.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
package gotables
import (
_ "encoding/json"
"fmt"
_ "os"
_ "strings"
"time"
yaml "gopkg.in/yaml.v3"
)
/*
Unmarshal YAML document to a *gotables.TableSet
*/
func NewTableSetFromYAML(yamlTableSetString string) (tableSet *TableSet, err error) {
/*
Note: Although the yamlTableSetString may (or may not) be the same in each case:
(1) GetTableSetAsYAML() produces a YAML document marshalled from:
map[string]interface{}
{"data":[][]interface{}{[]interface{}{11.1, 0x2, 97, 3}, []interface{}{22.2, 0x4, 98, 4}, []interface{}{33.3, 0x6, 99, 5}}
(2) but is parsed as:
map[string]interface{}
{"data":[] interface{}{[]interface{}{11.1, 2, 97, 3}, []interface{}{22.2, 4, 98, 4}, []interface{}{33.3, 6, 99, 5}}
The critical difference is that:
(i) "data" in (1) is a 2-dimensional array (rows by cols), whereas
(ii) "data" in (2) is an array of rows of maps.
For this reason, NewTableSetFromYAML parses the unmarshalled yaml differently from the way GetTableSetAsYAML() generates it.
*/
if yamlTableSetString == "" {
return nil, fmt.Errorf("%s: yamlTableSetString is empty", UtilFuncName())
}
var tableSetMap map[string]interface{}
err = yaml.Unmarshal([]byte(yamlTableSetString), &tableSetMap)
if err != nil {
return
}
// (1) Retrieve and process TableSet name.
var tableSetName string
var exists bool
tableSetName, exists = tableSetMap["tableSetName"].(string)
if !exists {
return nil, fmt.Errorf("%s %s: in YAML doc: 'tableSetName' is missing", UtilFuncSource(), UtilFuncName())
}
tableSet, err = NewTableSet(tableSetName)
if err != nil {
return
}
// (2) Retrieve and process tables.
var tablesMap []interface{}
var anyVal interface{}
anyVal, exists = tableSetMap["tables"]
tablesMap = anyVal.([]interface{})
if !exists {
return nil, fmt.Errorf("%s %s: in YAML doc: 'tables' is missing", UtilFuncSource(), UtilFuncName())
}
var tableMap map[string]interface{}
// (3) Loop through the array of tables.
for _, anyVal = range tablesMap {
tableMap = anyVal.(map[string]interface{})
var table *Table
table, err = newTableFromYAML_recursive(tableMap)
if err != nil {
return
}
err = tableSet.Append(table)
if err != nil {
return
}
}
return
}
func newTableFromYAML_recursive(tableMap map[string]interface{}) (table *Table, err error) {
var exists bool
/*
We don't know the order map values will be returned if we iterate over the map:
(1) tableName
(2) isStructShape (if there)
(3) metadata
(4) data (if any)
So we retrieve each of the 3 (possibly 2) top-level map values individually.
*/
// (1) Retrieve and process table name.
var tableName string
tableName, exists = tableMap["tableName"].(string)
if !exists {
err = fmt.Errorf("%s %s: in YAML doc: table is missing 'tableName'", UtilFuncSource(), UtilFuncName())
return
}
if len(tableName) > 0 {
table, err = NewTable(tableName)
if err != nil {
return
}
} else {
table = NewNilTable()
return
}
// If this optional isStructShape element is present, use it.
var isStructShape bool
isStructShape, exists = tableMap["isStructShape"].(bool)
if exists {
err = table.SetStructShape(isStructShape)
if err != nil {
return
}
}
// (2) Retrieve and process metadata.
var metadata []interface{}
metadata, exists = tableMap["metadata"].([]interface{})
if !exists {
err = fmt.Errorf("%s %s: in YAML doc: table 'metadata' is missing", UtilFuncSource(), UtilFuncName())
return
}
// Loop through the array of metadata.
for _, colNameAndType := range metadata {
var colName string
var colType string
var typeVal interface{}
for colName, typeVal = range colNameAndType.(map[string]interface{}) {
// There's only one map element here: colName and colType.
}
colType, ok := typeVal.(string)
if !ok {
err = fmt.Errorf("expecting colType string value from YAML but got type %T and value: %v", typeVal, typeVal)
return
}
colType = trimQuote(colType) // YAML likes to quote some strings.
err = table.AppendCol(colName, colType)
if err != nil {
table = nil
return
}
}
// (3) Retrieve and process data (if any).
var data [][]interface{}
data, exists = tableMap["data"].([][]interface{})
whatever, _ := tableMap["data"]
var dataMapSlice []interface{}
var dataMapSliceSlice [][]interface{}
switch whatever.(type) {
case [][]interface{}:
dataMapSliceSlice = whatever.([][]interface{})
data = dataMapSliceSlice
case []interface{}:
// Rewrite this nominal slice of interface{} as [][]interface{}
// Underneath it is "really" [][]interface{}
// Why this is so is a real puzzler, but this solution works.
dataMapSlice = whatever.([]interface{})
data = make([][]interface{}, len(dataMapSlice))
for i, el1 := range dataMapSlice {
for _, el2 := range el1.([]interface{}) {
data[i] = append(data[i], el2)
}
}
default:
}
whatever, exists = existsInMap(tableMap, "data")
if !exists {
// Zero rows in this table. That's okay.
return
}
// Loop through the array of rows.
var row []interface{}
for rowIndex := 0; rowIndex < len(data); rowIndex++ {
err = table.AppendRow()
if err != nil {
table = nil
return
}
row = data[rowIndex]
for colIndex := 0; colIndex < len(row); colIndex++ {
switch row[colIndex].(type) {
case uint:
err = table.SetUintByColIndex(colIndex, rowIndex, row[colIndex].(uint))
case int:
var intVal = row[colIndex].(int)
switch table.colTypes[colIndex] {
case "int":
err = table.SetIntByColIndex(colIndex, rowIndex, row[colIndex].(int))
case "uint":
var intVal int = row[colIndex].(int)
var uintVal uint = uint(intVal)
err = table.SetUintByColIndex(colIndex, rowIndex, uintVal)
case "int8":
err = table.SetInt8ByColIndex(colIndex, rowIndex, int8(intVal))
case "int16":
err = table.SetInt16ByColIndex(colIndex, rowIndex, int16(intVal))
case "int32":
err = table.SetInt32ByColIndex(colIndex, rowIndex, int32(intVal))
case "int64":
err = table.SetInt64ByColIndex(colIndex, rowIndex, int64(intVal))
case "uint8":
err = table.SetUint8ByColIndex(colIndex, rowIndex, uint8(intVal))
case "byte":
err = table.SetByteByColIndex(colIndex, rowIndex, uint8(intVal))
case "uint16":
err = table.SetUint16ByColIndex(colIndex, rowIndex, uint16(intVal))
case "uint32":
err = table.SetUint32ByColIndex(colIndex, rowIndex, uint32(intVal))
case "uint64":
err = table.SetUint64ByColIndex(colIndex, rowIndex, uint64(intVal))
case "float32":
err = table.SetFloat32ByColIndex(colIndex, rowIndex, float32(intVal))
case "time.Time":
err = table.SetTimeByColIndex(colIndex, rowIndex, row[colIndex].(time.Time))
case "rune":
err = table.SetRuneByColIndex(colIndex, rowIndex, rune(intVal))
default:
msg := invalidColTypeMsg(table.Name(), table.colTypes[colIndex])
err = fmt.Errorf("%s %s: %s", UtilFuncSource(), UtilFuncName(), msg)
table = nil
return
}
// Error handler for all cases.
if err != nil {
table = nil
return
}
case float32:
var float32Val float32 = row[colIndex].(float32)
err = table.SetFloat32ByColIndex(colIndex, rowIndex, float32Val)
case float64:
switch table.colTypes[colIndex] {
case "float32":
var float64Val float64 = row[colIndex].(float64)
err = table.SetFloat32ByColIndex(colIndex, rowIndex, float32(float64Val))
case "float64":
err = table.SetFloat64ByColIndex(colIndex, rowIndex, row[colIndex].(float64))
default:
msg := invalidColTypeMsg(table.Name(), table.colTypes[colIndex])
err = fmt.Errorf("%s %s: %s", UtilFuncSource(), UtilFuncName(), msg)
table = nil
return
}
case byte:
var byteVal byte = row[colIndex].(byte)
err = table.SetByteByColIndex(colIndex, rowIndex, byteVal)
case rune:
var runeVal rune = row[colIndex].(rune)
err = table.SetRuneByColIndex(colIndex, rowIndex, runeVal)
case string:
var stringVal string = row[colIndex].(string)
err = table.SetStringByColIndex(colIndex, rowIndex, stringVal)
case bool:
err = table.SetBoolByColIndex(colIndex, rowIndex, row[colIndex].(bool))
case time.Time:
err = table.SetTimeByColIndex(colIndex, rowIndex, row[colIndex].(time.Time))
case interface{}:
switch table.colTypes[colIndex] {
case "byte":
err = table.SetByteByColIndex(colIndex, rowIndex, row[colIndex].(byte))
case "uint":
var uint64Val uint64 = row[colIndex].(uint64)
err = table.SetUintByColIndex(colIndex, rowIndex, uint(uint64Val))
case "uint16":
err = table.SetUint16ByColIndex(colIndex, rowIndex, row[colIndex].(uint16))
case "uint32":
err = table.SetUint32ByColIndex(colIndex, rowIndex, row[colIndex].(uint32))
case "uint64":
err = table.SetUint64ByColIndex(colIndex, rowIndex, row[colIndex].(uint64))
case "int8":
err = table.SetInt8ByColIndex(colIndex, rowIndex, row[colIndex].(int8))
case "int16":
err = table.SetInt16ByColIndex(colIndex, rowIndex, row[colIndex].(int16))
case "int64":
err = table.SetInt64ByColIndex(colIndex, rowIndex, row[colIndex].(int64))
case "*Table":
var tableOut *Table
tableOut, err = newTableFromYAML_recursive(row[colIndex].(map[string]interface{}))
if err != nil {
return
}
err = table.SetTableByColIndex(colIndex, rowIndex, tableOut)
case "[]byte", "[]uint8":
var sliceVal []interface{}
var byteSliceVal []byte
switch row[colIndex].(type) {
case []byte:
byteSliceVal = row[colIndex].([]byte)
case []interface{}:
sliceVal = row[colIndex].([]interface{})
byteSliceVal = make([]byte, len(sliceVal))
for i := 0; i < len(sliceVal); i++ {
var intVal int = sliceVal[i].(int)
byteSliceVal[i] = byte(intVal)
}
case interface{}:
default:
}
switch table.colTypes[colIndex] {
case "[]byte":
err = table.SetByteSliceByColIndex(colIndex, rowIndex, byteSliceVal)
case "[]uint8":
err = table.SetUint8SliceByColIndex(colIndex, rowIndex, byteSliceVal)
default:
msg := invalidColTypeMsg(table.Name(), table.colTypes[colIndex])
err = fmt.Errorf("#1 %s %s: %s", UtilFuncSource(), UtilFuncName(), msg)
table = nil
return
}
default:
msg := invalidColTypeMsg(table.Name(), table.colTypes[colIndex])
err = fmt.Errorf("#2 %s %s: %s", UtilFuncSource(), UtilFuncName(), msg)
table = nil
return
}
// #1 Error handler for all cases.
if err != nil {
table = nil
return
}
case []interface{}:
case []byte:
case *Table:
default:
msg := invalidColTypeMsg(table.Name(), table.colTypes[colIndex])
err = fmt.Errorf("#3 %s %s: %s", UtilFuncSource(), UtilFuncName(), msg)
table = nil
return
}
// #3 Error handler for all cases.
if err != nil {
table = nil
return
}
}
}
return
}
func (tableSet *TableSet) GetTableSetAsYAML() (yamlString string, err error) {
if tableSet == nil {
return "", fmt.Errorf("%s tableSet.%s: table set is <nil>", UtilFuncSource(), UtilFuncName())
}
var yamlMap map[string]interface{}
yamlMap, err = tableSet.GetTableSetAsMap()
if err != nil {
return "", nil
}
var yamlBytes []byte
yamlBytes, err = yaml.Marshal(yamlMap)
if err != nil {
return "", nil
}
yamlString = string(yamlBytes)
return
}
func (tableSet *TableSet) GetTableSetAsMap() (yamlMap map[string]interface{}, err error) {
if tableSet == nil {
return nil, fmt.Errorf("%s tableSet.%s: table set is <nil>", UtilFuncSource(), UtilFuncName())
}
var yamlDoc map[string]interface{} = make(map[string]interface{}, 0)
yamlDoc["tableSetName"] = tableSet.Name()
var yamlTables []map[string]interface{} = make([]map[string]interface{}, tableSet.TableCount())
for tableIndex := 0; tableIndex < tableSet.TableCount(); tableIndex++ {
var table *Table
table, err = tableSet.GetTableByTableIndex(tableIndex)
if err != nil {
return
}
var yamlTable map[string]interface{}
yamlTable, err = table.getTableAsMap()
if err != nil {
return
}
yamlTables[tableIndex] = yamlTable
}
yamlDoc["tables"] = yamlTables
yamlMap = yamlDoc
return
}
func (table *Table) getTableAsMap() (yamlTable map[string]interface{}, err error) {
var yamlObject map[string]interface{} // Cell name and value pair.
var yamlTableData [][]interface{}
var yamlTableRow []interface{}
var visitTable = func(table *Table) (err error) {
// Used (and re-used) only in visitTable() function.
var yamlTableMetadata = make([]interface{}, table.ColCount())
yamlTable = make(map[string]interface{}, 0)
yamlTableData = make([][]interface{}, table.RowCount())
yamlTable["tableName"] = table.Name()
yamlTable["data"] = yamlTableData
if table.isStructShape {
yamlTable["isStructShape"] = true
}
// Build metadata map.
for colIndex := 0; colIndex < table.ColCount(); colIndex++ {
yamlObject = make(map[string]interface{}, 0)
if table.colTypes[colIndex] == "*Table" {
// Quote "*Table" to avoid YAML interpreting it as an alias.
yamlObject[table.colNames[colIndex]] = fmt.Sprintf("%q", table.colTypes[colIndex])
} else {
yamlObject[table.colNames[colIndex]] = table.colTypes[colIndex]
}
yamlTableMetadata[colIndex] = yamlObject
}
yamlTable["metadata"] = yamlTableMetadata
return
}
var visitRow = func(row Row) (err error) {
// Make a fresh yamlTableRow.
yamlTableRow = make([]interface{}, row.Table.ColCount())
// Assign it to yamlTableData.
yamlTableData[row.RowIndex] = yamlTableRow
return
}
var visitCell = func(walkDeep bool, cell CellInfo) (err error) {
var anyVal interface{}
switch cell.ColType {
case "string":
anyVal, err = cell.Table.GetStringByColIndex(cell.ColIndex, cell.RowIndex)
case "bool":
anyVal, err = cell.Table.GetBoolByColIndex(cell.ColIndex, cell.RowIndex)
case "rune":
anyVal, err = cell.Table.GetRuneByColIndex(cell.ColIndex, cell.RowIndex)
case "byte":
anyVal, err = cell.Table.GetByteByColIndex(cell.ColIndex, cell.RowIndex)
case "int":
anyVal, err = cell.Table.GetIntByColIndex(cell.ColIndex, cell.RowIndex)
case "int8":
anyVal, err = cell.Table.GetInt8ByColIndex(cell.ColIndex, cell.RowIndex)
case "int16":
anyVal, err = cell.Table.GetInt16ByColIndex(cell.ColIndex, cell.RowIndex)
case "int32":
anyVal, err = cell.Table.GetInt32ByColIndex(cell.ColIndex, cell.RowIndex)
case "int64":
anyVal, err = cell.Table.GetInt64ByColIndex(cell.ColIndex, cell.RowIndex)
case "uint":
anyVal, err = cell.Table.GetUintByColIndex(cell.ColIndex, cell.RowIndex)
case "uint8":
anyVal, err = cell.Table.GetUint8ByColIndex(cell.ColIndex, cell.RowIndex)
case "uint16":
anyVal, err = cell.Table.GetUint16ByColIndex(cell.ColIndex, cell.RowIndex)
case "uint32":
anyVal, err = cell.Table.GetUint32ByColIndex(cell.ColIndex, cell.RowIndex)
case "uint64":
anyVal, err = cell.Table.GetUint64ByColIndex(cell.ColIndex, cell.RowIndex)
case "float32":
anyVal, err = cell.Table.GetFloat32ByColIndex(cell.ColIndex, cell.RowIndex)
case "float64":
anyVal, err = cell.Table.GetFloat64ByColIndex(cell.ColIndex, cell.RowIndex)
case "[]uint8":
anyVal, err = cell.Table.GetUint8SliceByColIndex(cell.ColIndex, cell.RowIndex)
case "[]byte":
var byteSlice []byte
byteSlice, err = cell.Table.GetByteSliceByColIndex(cell.ColIndex, cell.RowIndex)
anyVal = byteSlice
case "time.Time":
anyVal, err = cell.Table.GetTimeByColIndex(cell.ColIndex, cell.RowIndex)
case "*Table":
var nestedTable *Table
nestedTable, err = cell.Table.GetTableByColIndex(cell.ColIndex, cell.RowIndex)
if err != nil {
return err
}
anyVal, err = nestedTable.getTableAsMap()
if err != nil {
return err
}
default:
msg := invalidColTypeMsg(table.Name(), cell.ColType)
err = fmt.Errorf("visitCell() YAML: %s", msg)
return err
}
// All errors in this switch are handled here.
if err != nil {
return err
}
yamlTableRow[cell.ColIndex] = anyVal
return
}
const walkDeep = false
var walkSafe WalkSafe = make(WalkSafe)
err = table.Walk(walkDeep, walkSafe, visitTable, visitRow, visitCell)
if err != nil {
return
}
return
}
func printYaml(yamlSlices []map[string][]map[string]interface{}, yamlArray []map[string]interface{}, yamlObject map[string]interface{}) {
var out []byte
var err error
if yamlArray != nil {
out, err = yaml.Marshal(yamlArray)
if err != nil {
fmt.Println("PARSE ERROR")
}
} else if yamlSlices != nil {
out, err = yaml.Marshal(yamlSlices)
if err != nil {
fmt.Println("PARSE ERROR")
}
} else if yamlObject != nil {
out, err = yaml.Marshal(yamlObject)
if err != nil {
fmt.Println("PARSE ERROR")
}
} else {
fmt.Println("ARG ERROR!")
}
fmt.Println("---\n" + string(out))
}
func printSlice(s []map[string]interface{}) string {
return fmt.Sprintf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
func printSliceOfSlice(s []map[string][]map[string]interface{}) string {
return fmt.Sprintf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
func printMap(m map[string]interface{}) string {
return fmt.Sprintf("len=%d %v\n", len(m), m)
}
func trimQuote(s string) string {
// From: https://stackoverflow.com/questions/44222554/how-to-remove-quotes-from-around-a-string-in-golang
if len(s) > 0 && s[0] == '"' {
s = s[1:]
}
if len(s) > 0 && s[len(s)-1] == '"' {
s = s[:len(s)-1]
}
return s
}
func isValidYAML(yamlString string, yamlMap map[string]interface{}) (isValid bool, err error) {
if yamlString == "" && yamlMap == nil {
err = fmt.Errorf("%s: yamlString and yamlMap are both empty", UtilFuncName())
}
var tableSet *TableSet
if yamlString != "" {
tableSet, err = NewTableSetFromYAML(yamlString)
if err != nil {
err = fmt.Errorf("isValidYAML(): %v", err)
return
}
var rowCount = 0
for tableIndex := 0; tableIndex < tableSet.TableCount(); tableIndex++ {
var table *Table
table, err = tableSet.GetTableByTableIndex(tableIndex)
if err != nil {
err = fmt.Errorf("isValidYAML(): %v", err)
return
}
rowCount += table.RowCount()
}
if rowCount == 0 {
err = fmt.Errorf("%s: from yamlString: tableSet [[%s]] with %d tables has 0 rows",
UtilFuncName(), tableSet.Name(), tableSet.TableCount())
err = fmt.Errorf("isValidYAML(): %v", err)
return
}
isValid = true
}
if yamlMap != nil {
var yamlBytes []byte
yamlBytes, err = yaml.Marshal(yamlMap)
if err != nil {
err = fmt.Errorf("isValidYAML(): %v", err)
return
}
yamlString = string(yamlBytes)
tableSet, err = NewTableSetFromYAML(yamlString)
if err != nil {
// See if it is a table.
errFromTableSet := err
_, err = newTableFromYAML_recursive(yamlMap)
if err != nil {
err = fmt.Errorf("isValidYAML(): %v (also %v)", err, errFromTableSet)
return
}
}
var rowCount = 0
for tableIndex := 0; tableIndex < tableSet.TableCount(); tableIndex++ {
var table *Table
table, err = tableSet.GetTableByTableIndex(tableIndex)
if err != nil {
err = fmt.Errorf("isValidYAML(): %v", err)
return
}
rowCount += table.RowCount()
}
if rowCount == 0 {
err = fmt.Errorf("%s: from yamlString: tableSet [[%s]] with %d tables has 0 rows",
UtilFuncName(), tableSet.Name(), tableSet.TableCount())
err = fmt.Errorf("isValidYAML(): %v", err)
return
}
isValid = true
}
return
}
func dataExists(yamlTable map[string]interface{}, sourceLineNumber int) string {
_, exists := yamlTable["data"]
return fmt.Sprintf(`ggg "data" exists = %t called by %s at %d`, exists, UtilFuncCaller(), sourceLineNumber)
}
func metadataExists(yamlTable map[string]interface{}, sourceLineNumber int) string {
_, exists := yamlTable["metadata"].([]interface{})
return fmt.Sprintf(`ggg "metadata" exists = %t called by %s at %d`, exists, UtilFuncCaller(), sourceLineNumber)
}
func tableNameExists(yamlTable map[string]interface{}, sourceLineNumber int) string {
_, exists := yamlTable["tableName"].(interface{})
return fmt.Sprintf(`ggg "tableName" exists = %t called by %s at %d`, exists, UtilFuncCaller(), sourceLineNumber)
}
func existsInMap(tableMap map[string]interface{}, searchKey string) (element interface{}, exists bool) {
var key string
for key, element = range tableMap {
if key == searchKey {
return element, true
}
}
return nil, false
}