From 24cb08c6b79b50a31ea1d24989212ba08dc60dd6 Mon Sep 17 00:00:00 2001 From: Arnas Udovic Date: Wed, 10 Jan 2024 08:34:50 +0200 Subject: [PATCH] zordTree up --- collector.go | 12 ++++++++++-- go.mod | 4 ++-- go.sum | 6 ++++-- main.go | 11 ++++++++--- server.go | 23 ++++++++++++++++------- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/collector.go b/collector.go index 587fc1d..eaac684 100644 --- a/collector.go +++ b/collector.go @@ -1,9 +1,17 @@ package main import ( - zord_tree "g.arns.lt/zordsdavini/zord-tree" "log" "os" + + zord_tree "g.arns.lt/zordsdavini/zord-tree" +) + +var config = zord_tree.NewConfig( + []string{".md"}, + "__a", + customMeta, + []string{"\\.sync_.{12}\\.db"}, ) func Collect() { @@ -14,6 +22,6 @@ func Collect() { } log.Println("Collect: pre") - _ = zord_tree.PopulateTree(source, meta, customMeta) + _ = zord_tree.PopulateTree(source, meta, config) log.Println("Collect: post") } diff --git a/go.mod b/go.mod index 4b286be..ad844e9 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module g.arns.lt/zordsdavini/arns-lt-tree-push-service -go 1.19 +go 1.21 require ( - g.arns.lt/zordsdavini/zord-tree v0.3.1 + g.arns.lt/zordsdavini/zord-tree v0.4.0 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.1 ) diff --git a/go.sum b/go.sum index ffb9a76..3d3f3e5 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= g.arns.lt/zordsdavini/abcex v1.0.0 h1:qQqlZ4DMfethCGK4I6yGaLqMrTzKNIshqpINd1l3t0E= g.arns.lt/zordsdavini/abcex v1.0.0/go.mod h1:YRcJgts3XZwI+LEkngpfUab3DkUAW387Irpr43hIym8= -g.arns.lt/zordsdavini/zord-tree v0.3.1 h1:oBXWJ85zCUEhcNDf5YNLaWg5QfsPw3Fw0ngWWsuuisA= -g.arns.lt/zordsdavini/zord-tree v0.3.1/go.mod h1:HG++MTNUD8oQHrkTdVnClm0q82lGumASn4GWJtWQApY= +g.arns.lt/zordsdavini/zord-tree v0.4.0 h1:Z/fyhcZV3XUZln3iytV2AIwIcwe9TjfXX84VRq/umMk= +g.arns.lt/zordsdavini/zord-tree v0.4.0/go.mod h1:FffR6V3ptOUEaufeu3mf2s0Ie/qqoyYQQVfVLlFZsDo= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -47,9 +47,11 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ= +github.com/otiai10/copy v1.6.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= diff --git a/main.go b/main.go index a295ef0..19a9363 100644 --- a/main.go +++ b/main.go @@ -6,9 +6,14 @@ import ( ) var ( - source string - key string - meta = []string{"description", "lang", "copyright", "created"} //_ = zord_tree.PopulateTree(cfg.MdTree.Path, cfg.MdTree.DPath, meta) + source string + key string + meta = []string{ + "description", + "lang", + "copyright", + "created", + } //_ = zord_tree.PopulateTree(cfg.MdTree.Path, cfg.MdTree.DPath, meta) customMeta = make(map[string]func() string) ) diff --git a/server.go b/server.go index 0077e8a..ece0d6f 100644 --- a/server.go +++ b/server.go @@ -3,13 +3,14 @@ package main import ( "context" "fmt" - zordTree "g.arns.lt/zordsdavini/zord-tree" - "google.golang.org/grpc" "io" "log" "net" "os" "path" + + zordTree "g.arns.lt/zordsdavini/zord-tree" + "google.golang.org/grpc" ) type server struct { @@ -18,7 +19,7 @@ type server struct { func (TreeManagerServer *server) GetSummery(_ context.Context, in *TreeRequest) (*Tree, error) { log.Println(in) - tree, err := zordTree.BuildTree(source, meta) + tree, err := zordTree.BuildTree(source, meta, config) if err != nil { log.Fatal(err) return nil, err @@ -50,7 +51,7 @@ func (TreeManagerServer *server) GetSummery(_ context.Context, in *TreeRequest) func (TreeManagerServer *server) GetFile(_ context.Context, in *FileRequest) (*FileContent, error) { log.Println(in) - tree, err := zordTree.BuildTree(source, meta) + tree, err := zordTree.BuildTree(source, meta, config) if err != nil { log.Fatal(err) return nil, err @@ -66,7 +67,10 @@ func (TreeManagerServer *server) GetFile(_ context.Context, in *FileRequest) (*F return &fileContent, nil } -func (TreeManagerServer *server) RebuildTree(ctx context.Context, in *TreeSecret) (*RebuildResponse, error) { +func (TreeManagerServer *server) RebuildTree( + ctx context.Context, + in *TreeSecret, +) (*RebuildResponse, error) { log.Println(in, key) success := false if in.Key == key { @@ -78,8 +82,13 @@ func (TreeManagerServer *server) RebuildTree(ctx context.Context, in *TreeSecret return &response, nil } -func (TreeManagerServer *server) DownloadAttachment(in *AttachmentRequest, responseStream TreeManager_DownloadAttachmentServer) error { - file, err := os.Open(path.Clean(fmt.Sprintf("%s/%s/%s", source, zordTree.AttachmentDirName, in.Path))) +func (TreeManagerServer *server) DownloadAttachment( + in *AttachmentRequest, + responseStream TreeManager_DownloadAttachmentServer, +) error { + file, err := os.Open( + path.Clean(fmt.Sprintf("%s/%s/%s", source, &config.AttachmentDirName, in.Path)), + ) if err != nil { return err }