zordTree up

This commit is contained in:
Arnas Udovic 2024-01-10 08:34:50 +02:00
parent 5c946cef11
commit 24cb08c6b7
5 changed files with 40 additions and 16 deletions

View file

@ -1,9 +1,17 @@
package main package main
import ( import (
zord_tree "g.arns.lt/zordsdavini/zord-tree"
"log" "log"
"os" "os"
zord_tree "g.arns.lt/zordsdavini/zord-tree"
)
var config = zord_tree.NewConfig(
[]string{".md"},
"__a",
customMeta,
[]string{"\\.sync_.{12}\\.db"},
) )
func Collect() { func Collect() {
@ -14,6 +22,6 @@ func Collect() {
} }
log.Println("Collect: pre") log.Println("Collect: pre")
_ = zord_tree.PopulateTree(source, meta, customMeta) _ = zord_tree.PopulateTree(source, meta, config)
log.Println("Collect: post") log.Println("Collect: post")
} }

4
go.mod
View file

@ -1,9 +1,9 @@
module g.arns.lt/zordsdavini/arns-lt-tree-push-service module g.arns.lt/zordsdavini/arns-lt-tree-push-service
go 1.19 go 1.21
require ( 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/grpc v1.48.0
google.golang.org/protobuf v1.28.1 google.golang.org/protobuf v1.28.1
) )

6
go.sum
View file

@ -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= 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 h1:qQqlZ4DMfethCGK4I6yGaLqMrTzKNIshqpINd1l3t0E=
g.arns.lt/zordsdavini/abcex v1.0.0/go.mod h1:YRcJgts3XZwI+LEkngpfUab3DkUAW387Irpr43hIym8= 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.4.0 h1:Z/fyhcZV3XUZln3iytV2AIwIcwe9TjfXX84VRq/umMk=
g.arns.lt/zordsdavini/zord-tree v0.3.1/go.mod h1:HG++MTNUD8oQHrkTdVnClm0q82lGumASn4GWJtWQApY= 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/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/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= 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.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.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 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/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/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 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/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/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= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=

11
main.go
View file

@ -6,9 +6,14 @@ import (
) )
var ( var (
source string source string
key string key string
meta = []string{"description", "lang", "copyright", "created"} //_ = zord_tree.PopulateTree(cfg.MdTree.Path, cfg.MdTree.DPath, meta) meta = []string{
"description",
"lang",
"copyright",
"created",
} //_ = zord_tree.PopulateTree(cfg.MdTree.Path, cfg.MdTree.DPath, meta)
customMeta = make(map[string]func() string) customMeta = make(map[string]func() string)
) )

View file

@ -3,13 +3,14 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
zordTree "g.arns.lt/zordsdavini/zord-tree"
"google.golang.org/grpc"
"io" "io"
"log" "log"
"net" "net"
"os" "os"
"path" "path"
zordTree "g.arns.lt/zordsdavini/zord-tree"
"google.golang.org/grpc"
) )
type server struct { type server struct {
@ -18,7 +19,7 @@ type server struct {
func (TreeManagerServer *server) GetSummery(_ context.Context, in *TreeRequest) (*Tree, error) { func (TreeManagerServer *server) GetSummery(_ context.Context, in *TreeRequest) (*Tree, error) {
log.Println(in) log.Println(in)
tree, err := zordTree.BuildTree(source, meta) tree, err := zordTree.BuildTree(source, meta, config)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
return nil, 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) { func (TreeManagerServer *server) GetFile(_ context.Context, in *FileRequest) (*FileContent, error) {
log.Println(in) log.Println(in)
tree, err := zordTree.BuildTree(source, meta) tree, err := zordTree.BuildTree(source, meta, config)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
return nil, err return nil, err
@ -66,7 +67,10 @@ func (TreeManagerServer *server) GetFile(_ context.Context, in *FileRequest) (*F
return &fileContent, nil 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) log.Println(in, key)
success := false success := false
if in.Key == key { if in.Key == key {
@ -78,8 +82,13 @@ func (TreeManagerServer *server) RebuildTree(ctx context.Context, in *TreeSecret
return &response, nil return &response, nil
} }
func (TreeManagerServer *server) DownloadAttachment(in *AttachmentRequest, responseStream TreeManager_DownloadAttachmentServer) error { func (TreeManagerServer *server) DownloadAttachment(
file, err := os.Open(path.Clean(fmt.Sprintf("%s/%s/%s", source, zordTree.AttachmentDirName, in.Path))) 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 { if err != nil {
return err return err
} }