Skip to content

Commit

Permalink
chore: another refactor for main
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsper2nd committed Apr 1, 2024
1 parent b5e5b79 commit 94241e7
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions generate/idcac/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,27 +163,49 @@ func main() {
var commons, rules string
var javascriptFixes = make(map[int]string)

err = jsonextract.Reader(strings.NewReader(string(rulesContent)), func(b []byte) error {
var data []interface{}
if err := json.Unmarshal(b, &data); err != nil {
return err
}
// err = jsonextract.Reader(strings.NewReader(string(rulesContent)), func(b []byte) error {
// var data []interface{}
// if err := json.Unmarshal(b, &data); err != nil {
// return err
// }

// for _, item := range data {
// if rule, ok := item.(map[string]interface{}); ok {
// if isRules(rule) {
// rules = toJSONString(rule)
// break // Assuming there's only one ruleset, you can adjust this logic if needed
// }
// } else if commonsData, ok := item.(map[string]interface{}); ok {
// if isCommons(commonsData) {
// commons = toJSONString(commonsData)
// break // Assuming there's only one commons set, you can adjust this logic if needed
// }
// }
// }
// return nil
// })

err = jsonextract.Reader(strings.NewReader(string(rulesContent)), func(b []byte) error {
var data []interface{}
if err := json.Unmarshal(b, &data); err != nil {
return err
}

for _, item := range data {
if rulesArray, ok := item.([]interface{}); ok {
for _, rule := range rulesArray {
if ruleMap, ok := rule.(map[string]interface{}); ok {
if isRules(ruleMap) {
rules = toJSONString(ruleMap)
return nil // Assuming we found the rules and can exit the loop
}
}
}
}
}
return fmt.Errorf("no rules found in the rules.js file")
})

for _, item := range data {
if rule, ok := item.(map[string]interface{}); ok {
if isRules(rule) {
rules = toJSONString(rule)
break // Assuming there's only one ruleset, you can adjust this logic if needed
}
} else if commonsData, ok := item.(map[string]interface{}); ok {
if isCommons(commonsData) {
commons = toJSONString(commonsData)
break // Assuming there's only one commons set, you can adjust this logic if needed
}
}
}
return nil
})

if err != nil {
log.Fatalf("failed to read/converting rules file: %s\n", err.Error())
Expand Down

0 comments on commit 94241e7

Please sign in to comment.