Fix client imports
This commit is contained in:
parent
a3814f644c
commit
6470454221
3
.gitignore
vendored
3
.gitignore
vendored
@ -14,6 +14,9 @@
|
|||||||
# Golang vendor folder
|
# Golang vendor folder
|
||||||
vendor
|
vendor
|
||||||
|
|
||||||
|
# database
|
||||||
|
db
|
||||||
|
|
||||||
# Intelli-J files
|
# Intelli-J files
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
|
||||||
"golang.org/x/exp/rand"
|
"math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Controller interface {
|
type Controller interface {
|
||||||
|
|||||||
@ -4,12 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/document"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/document/textdocument"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ocache"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ocache"
|
||||||
|
"go.uber.org/zap"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,13 +24,29 @@ const spaceKey ctxKey = 0
|
|||||||
type treeCache struct {
|
type treeCache struct {
|
||||||
gcttl int
|
gcttl int
|
||||||
cache ocache.OCache
|
cache ocache.OCache
|
||||||
docService document.Service
|
|
||||||
clientService clientspace.Service
|
clientService clientspace.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
type TreeCache interface {
|
type TreeCache interface {
|
||||||
treegetter.TreeGetter
|
treegetter.TreeGetter
|
||||||
GetDocument(ctx context.Context, spaceId, id string) (doc document.TextDocument, err error)
|
GetDocument(ctx context.Context, spaceId, id string) (doc textdocument.TextDocument, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type updateListener struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *updateListener) Update(tree tree.ObjectTree) {
|
||||||
|
log.With(
|
||||||
|
zap.Strings("heads", tree.Heads()),
|
||||||
|
zap.String("tree id", tree.ID())).
|
||||||
|
Debug("updating tree")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *updateListener) Rebuild(tree tree.ObjectTree) {
|
||||||
|
log.With(
|
||||||
|
zap.Strings("heads", tree.Heads()),
|
||||||
|
zap.String("tree id", tree.ID())).
|
||||||
|
Debug("rebuilding tree")
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ttl int) TreeCache {
|
func New(ttl int) TreeCache {
|
||||||
@ -48,7 +65,6 @@ func (c *treeCache) Close(ctx context.Context) (err error) {
|
|||||||
|
|
||||||
func (c *treeCache) Init(a *app.App) (err error) {
|
func (c *treeCache) Init(a *app.App) (err error) {
|
||||||
c.clientService = a.MustComponent(clientspace.CName).(clientspace.Service)
|
c.clientService = a.MustComponent(clientspace.CName).(clientspace.Service)
|
||||||
c.docService = a.MustComponent(document.CName).(document.Service)
|
|
||||||
c.cache = ocache.New(
|
c.cache = ocache.New(
|
||||||
func(ctx context.Context, id string) (value ocache.Object, err error) {
|
func(ctx context.Context, id string) (value ocache.Object, err error) {
|
||||||
spaceId := ctx.Value(spaceKey).(string)
|
spaceId := ctx.Value(spaceKey).(string)
|
||||||
@ -56,7 +72,7 @@ func (c *treeCache) Init(a *app.App) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return document.NewTextDocument(context.Background(), space, id, c.docService)
|
return textdocument.NewTextDocument(context.Background(), space, id, &updateListener{})
|
||||||
},
|
},
|
||||||
ocache.WithLogger(log.Sugar()),
|
ocache.WithLogger(log.Sugar()),
|
||||||
ocache.WithGCPeriod(time.Minute),
|
ocache.WithGCPeriod(time.Minute),
|
||||||
@ -69,13 +85,13 @@ func (c *treeCache) Name() (name string) {
|
|||||||
return treegetter.CName
|
return treegetter.CName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *treeCache) GetDocument(ctx context.Context, spaceId, id string) (doc document.TextDocument, err error) {
|
func (c *treeCache) GetDocument(ctx context.Context, spaceId, id string) (doc textdocument.TextDocument, err error) {
|
||||||
ctx = context.WithValue(ctx, spaceKey, spaceId)
|
ctx = context.WithValue(ctx, spaceKey, spaceId)
|
||||||
v, err := c.cache.Get(ctx, id)
|
v, err := c.cache.Get(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
doc = v.(document.TextDocument)
|
doc = v.(textdocument.TextDocument)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,8 +34,9 @@ var log = logger.NewNamed("main")
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
flagConfigFile = flag.String("c", "etc/client.yml", "path to config file")
|
flagConfigFile = flag.String("c", "etc/client.yml", "path to config file")
|
||||||
flagVersion = flag.Bool("v", false, "show version and exit")
|
// we can't use "v" here because of glog init (through badger) setting flag.Bool with "v"
|
||||||
flagHelp = flag.Bool("h", false, "show help and exit")
|
flagVersion = flag.Bool("ver", false, "show version and exit")
|
||||||
|
flagHelp = flag.Bool("h", false, "show help and exit")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@ -4,18 +4,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace/clientcache"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace/clientcache"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/document/textdocument"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener"
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
|
|
||||||
"go.uber.org/zap"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service interface {
|
type Service interface {
|
||||||
app.Component
|
app.Component
|
||||||
updatelistener.UpdateListener
|
|
||||||
CreateDocument(spaceId string) (id string, err error)
|
CreateDocument(spaceId string) (id string, err error)
|
||||||
AllDocumentIds(spaceId string) (ids []string, err error)
|
AllDocumentIds(spaceId string) (ids []string, err error)
|
||||||
AddText(spaceId, documentId, text string) (err error)
|
AddText(spaceId, documentId, text string) (err error)
|
||||||
@ -52,7 +49,7 @@ func (s *service) CreateDocument(spaceId string) (id string, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
doc, err := createTextDocument(context.Background(), space, s.account, s)
|
doc, err := textdocument.CreateTextDocument(context.Background(), space, s.account, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -84,17 +81,3 @@ func (s *service) DumpDocumentTree(spaceId, documentId string) (dump string, err
|
|||||||
}
|
}
|
||||||
return doc.Tree().DebugDump()
|
return doc.Tree().DebugDump()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Update(tree tree.ObjectTree) {
|
|
||||||
log.With(
|
|
||||||
zap.Strings("heads", tree.Heads()),
|
|
||||||
zap.String("tree id", tree.ID())).
|
|
||||||
Debug("updating tree")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) Rebuild(tree tree.ObjectTree) {
|
|
||||||
log.With(
|
|
||||||
zap.Strings("heads", tree.Heads()),
|
|
||||||
zap.String("tree id", tree.ID())).
|
|
||||||
Debug("rebuilding tree")
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package document
|
package textdocument
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -23,7 +23,7 @@ type textDocument struct {
|
|||||||
account account.Service
|
account account.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTextDocument(
|
func CreateTextDocument(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
space commonspace.Space,
|
space commonspace.Space,
|
||||||
account account.Service,
|
account account.Service,
|
||||||
@ -8,6 +8,7 @@ require (
|
|||||||
github.com/anytypeio/go-anytype-infrastructure-experiments/common v0.0.0-00010101000000-000000000000
|
github.com/anytypeio/go-anytype-infrastructure-experiments/common v0.0.0-00010101000000-000000000000
|
||||||
github.com/dgraph-io/badger/v3 v3.2103.3
|
github.com/dgraph-io/badger/v3 v3.2103.3
|
||||||
github.com/gogo/protobuf v1.3.2
|
github.com/gogo/protobuf v1.3.2
|
||||||
|
go.uber.org/zap v1.23.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -59,7 +60,6 @@ require (
|
|||||||
go.opencensus.io v0.23.0 // indirect
|
go.opencensus.io v0.23.0 // indirect
|
||||||
go.uber.org/atomic v1.10.0 // indirect
|
go.uber.org/atomic v1.10.0 // indirect
|
||||||
go.uber.org/multierr v1.8.0 // indirect
|
go.uber.org/multierr v1.8.0 // indirect
|
||||||
go.uber.org/zap v1.23.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
||||||
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
|
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
|
||||||
golang.org/x/net v0.0.0-20220920183852-bf014ff85ad5 // indirect
|
golang.org/x/net v0.0.0-20220920183852-bf014ff85ad5 // indirect
|
||||||
|
|||||||
@ -54,3 +54,7 @@ func (c Config) GetGRPCServer() GrpcServer {
|
|||||||
func (c Config) GetAccount() Account {
|
func (c Config) GetAccount() Account {
|
||||||
return c.Account
|
return c.Account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Config) GetMetric() Metric {
|
||||||
|
return c.Metric
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user