All checks were successful
Build and push image / deploy (push) Successful in 1m44s
42 lines
815 B
Go
42 lines
815 B
Go
package category
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"strings"
|
|
|
|
"gitea.home.4it.me/dilap54/platiparser/plati"
|
|
)
|
|
|
|
func FilterBySubstring(substring string, categories plati.Categories) plati.Categories {
|
|
out := make(plati.Categories, 0)
|
|
for _, c := range categories {
|
|
if len(c.Children) > 0 {
|
|
out = append(out, FilterBySubstring(substring, c.Children)...)
|
|
continue
|
|
}
|
|
|
|
if strings.Contains(c.FlatName, substring) {
|
|
out = append(out, c)
|
|
}
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
func OpenCategories(fileName string) plati.CategoriesResponse {
|
|
f, err := os.OpenFile(fileName, os.O_RDONLY, 0400)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer f.Close()
|
|
|
|
out := plati.CategoriesResponse{}
|
|
if err := json.NewDecoder(f).Decode(&out); err != nil {
|
|
panic(err)
|
|
}
|
|
out.Content.FlatNames("")
|
|
out.Content.FixParentID(0)
|
|
return out
|
|
}
|