change port; fix categories
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Arnas Udovicius 2022-08-17 14:32:20 +03:00
parent c48b8c6531
commit 5f9b822a02
2 changed files with 21 additions and 8 deletions

View file

@ -1,6 +1,9 @@
package main package main
import zord_tree "g.arns.lt/zordsdavini/zord-tree" import (
zord_tree "g.arns.lt/zordsdavini/zord-tree"
"strings"
)
type FSummery struct { type FSummery struct {
Name string Name string
@ -8,12 +11,15 @@ type FSummery struct {
Description string Description string
Id string Id string
Lang string Lang string
Created string
Copyright string
Tags []string Tags []string
} }
type TSummery struct { type TSummery struct {
Files []FSummery Files []FSummery
Tags map[string]int Tags map[string]int
Categories map[string]int
} }
type FileContent struct { type FileContent struct {
@ -22,15 +28,20 @@ type FileContent struct {
} }
func FormatTreeSummery(tree zord_tree.Tree) TSummery { func FormatTreeSummery(tree zord_tree.Tree) TSummery {
ts := TSummery{Tags: map[string]int{}} ts := TSummery{Tags: map[string]int{}, Categories: map[string]int{}}
readTree(tree, &ts) readTree(tree, &ts, true)
return ts return ts
} }
func readTree(tree zord_tree.Tree, ts *TSummery) { func readTree(tree zord_tree.Tree, ts *TSummery, isRoot bool) {
for _, subtree := range tree.Dirs { for _, subtree := range tree.Dirs {
readTree(subtree, ts) readTree(subtree, ts, false)
category := strings.Replace(subtree.Path, tree.Path, "", 1)
category = strings.Replace(category, "/", "", 1)
if isRoot {
ts.Categories[category]++
}
} }
for _, file := range tree.Files { for _, file := range tree.Files {
@ -40,6 +51,8 @@ func readTree(tree zord_tree.Tree, ts *TSummery) {
Description: file.Meta["description"], Description: file.Meta["description"],
Id: file.Id, Id: file.Id,
Lang: file.Meta["lang"], Lang: file.Meta["lang"],
Created: file.Meta["created"],
Copyright: file.Meta["copyright"],
Tags: file.Tags, Tags: file.Tags,
}) })
for _, tag := range file.Tags { for _, tag := range file.Tags {

View file

@ -32,7 +32,7 @@ func Run() {
panic(err) panic(err)
} }
ln, err := net.Listen("tcp", ":8001") ln, err := net.Listen("tcp", ":8301")
if err != nil { if err != nil {
fmt.Println("Error starting server: " + err.Error()) fmt.Println("Error starting server: " + err.Error())
} }