add parsing sumpays
All checks were successful
Build and push image / deploy (push) Successful in 1m44s
All checks were successful
Build and push image / deploy (push) Successful in 1m44s
This commit is contained in:
41
internal/category/default.go
Normal file
41
internal/category/default.go
Normal file
@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user