From bf5a96071425add2056f28d15e67e6e2c1c8b5f2 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Fri, 23 Oct 2020 16:30:23 +0200 Subject: [PATCH] Reformat responses --- accounts/pkg/command/rebuild_index.go | 4 ++-- accounts/pkg/service/v0/index.go | 20 ++++++++------------ accounts/pkg/storage/cs3.go | 8 ++++---- accounts/pkg/storage/disk.go | 8 ++++---- accounts/pkg/storage/repo.go | 12 ++---------- 5 files changed, 20 insertions(+), 32 deletions(-) diff --git a/accounts/pkg/command/rebuild_index.go b/accounts/pkg/command/rebuild_index.go index b4df1d55f2..3f37023619 100644 --- a/accounts/pkg/command/rebuild_index.go +++ b/accounts/pkg/command/rebuild_index.go @@ -20,12 +20,12 @@ func DeleteIndex(cdf *config.Config) *cli.Command { idxSvcID := "com.owncloud.api.accounts" idxSvc := index.NewIndexService(idxSvcID, grpc.NewClient()) - rsp, err := idxSvc.RebuildIndex(context.Background(), &index.RebuildIndexRequest{}) + _, err := idxSvc.RebuildIndex(context.Background(), &index.RebuildIndexRequest{}) if err != nil { return err } - fmt.Printf("deleted: %+v", rsp.Indices) + fmt.Print("index rebuilt successfully") return nil }, } diff --git a/accounts/pkg/service/v0/index.go b/accounts/pkg/service/v0/index.go index e62a3b88df..5bb3f49bcb 100644 --- a/accounts/pkg/service/v0/index.go +++ b/accounts/pkg/service/v0/index.go @@ -70,27 +70,23 @@ func recreateContainers(idx *indexer.Indexer, cfg *config.Config) error { // reindexDocuments loads all existing documents and adds them to the index. func reindexDocuments(ctx context.Context, repo storage.Repo, index *indexer.Indexer) error { - accounts := &storage.Accounts{ - Accounts: make([]*proto.Account, 0), - } - if err := repo.LoadAccounts(ctx, accounts); err != nil { + accounts := make([]*proto.Account, 0) + if err := repo.LoadAccounts(ctx, &accounts); err != nil { return err } - for i := range accounts.Accounts { - _, err := index.Add(accounts.Accounts[i]) + for i := range accounts { + _, err := index.Add(accounts[i]) if err != nil { return err } } - groups := &storage.Groups{ - Groups: make([]*proto.Group, 0), - } - if err := repo.LoadGroups(ctx, groups); err != nil { + groups := make([]*proto.Group, 0) + if err := repo.LoadGroups(ctx, &groups); err != nil { return err } - for i := range groups.Groups { - _, err := index.Add(groups.Groups[i]) + for i := range groups { + _, err := index.Add(groups[i]) if err != nil { return err } diff --git a/accounts/pkg/storage/cs3.go b/accounts/pkg/storage/cs3.go index 0fdbcc3033..af41f95ed6 100644 --- a/accounts/pkg/storage/cs3.go +++ b/accounts/pkg/storage/cs3.go @@ -96,7 +96,7 @@ func (r CS3Repo) LoadAccount(ctx context.Context, id string, a *proto.Account) ( } // LoadAccounts loads all the accounts from the cs3 api -func (r CS3Repo) LoadAccounts(ctx context.Context, a *Accounts) (err error) { +func (r CS3Repo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err error) { t, err := r.authenticate(ctx) if err != nil { return err @@ -120,7 +120,7 @@ func (r CS3Repo) LoadAccounts(ctx context.Context, a *Accounts) (err error) { log.Err(err).Msg("could not load account") continue } - a.Accounts = append(a.Accounts, acc) + *a = append(*a, acc) } return nil } @@ -210,7 +210,7 @@ func (r CS3Repo) LoadGroup(ctx context.Context, id string, g *proto.Group) (err } // LoadGroups loads all the groups from the cs3 api -func (r CS3Repo) LoadGroups(ctx context.Context, g *Groups) (err error) { +func (r CS3Repo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error) { t, err := r.authenticate(ctx) if err != nil { return err @@ -234,7 +234,7 @@ func (r CS3Repo) LoadGroups(ctx context.Context, g *Groups) (err error) { log.Err(err).Msg("could not load account") continue } - g.Groups = append(g.Groups, grp) + *g = append(*g, grp) } return nil } diff --git a/accounts/pkg/storage/disk.go b/accounts/pkg/storage/disk.go index 4de84d2b93..4d09e61b43 100644 --- a/accounts/pkg/storage/disk.go +++ b/accounts/pkg/storage/disk.go @@ -71,7 +71,7 @@ func (r DiskRepo) LoadAccount(ctx context.Context, id string, a *proto.Account) } // LoadAccounts loads all the accounts from the local filesystem -func (r DiskRepo) LoadAccounts(ctx context.Context, a *Accounts) (err error) { +func (r DiskRepo) LoadAccounts(ctx context.Context, a *[]*proto.Account) (err error) { root := filepath.Join(r.cfg.Repo.Disk.Path, accountsFolder) return filepath.Walk(root, func(path string, info os.FileInfo, err error) error { acc := &proto.Account{} @@ -79,7 +79,7 @@ func (r DiskRepo) LoadAccounts(ctx context.Context, a *Accounts) (err error) { r.log.Err(err).Msg("could not load account") return nil } - a.Accounts = append(a.Accounts, acc) + *a = append(*a, acc) return nil }) } @@ -133,7 +133,7 @@ func (r DiskRepo) LoadGroup(ctx context.Context, id string, g *proto.Group) (err } // LoadGroups loads all the groups from the local filesystem -func (r DiskRepo) LoadGroups(ctx context.Context, g *Groups) (err error) { +func (r DiskRepo) LoadGroups(ctx context.Context, g *[]*proto.Group) (err error) { root := filepath.Join(r.cfg.Repo.Disk.Path, groupsFolder) return filepath.Walk(root, func(path string, info os.FileInfo, err error) error { grp := &proto.Group{} @@ -141,7 +141,7 @@ func (r DiskRepo) LoadGroups(ctx context.Context, g *Groups) (err error) { r.log.Err(err).Msg("could not load group") return nil } - g.Groups = append(g.Groups, grp) + *g = append(*g, grp) return nil }) } diff --git a/accounts/pkg/storage/repo.go b/accounts/pkg/storage/repo.go index bb3e1a6a7d..739dff43a8 100644 --- a/accounts/pkg/storage/repo.go +++ b/accounts/pkg/storage/repo.go @@ -11,22 +11,14 @@ const ( groupsFolder = "groups" ) -type Accounts struct { - Accounts []*proto.Account -} - -type Groups struct { - Groups []*proto.Group -} - // Repo defines the storage operations type Repo interface { WriteAccount(ctx context.Context, a *proto.Account) (err error) LoadAccount(ctx context.Context, id string, a *proto.Account) (err error) - LoadAccounts(ctx context.Context, a *Accounts) (err error) + LoadAccounts(ctx context.Context, a *[]*proto.Account) (err error) DeleteAccount(ctx context.Context, id string) (err error) WriteGroup(ctx context.Context, g *proto.Group) (err error) LoadGroup(ctx context.Context, id string, g *proto.Group) (err error) - LoadGroups(ctx context.Context, g *Groups) (err error) + LoadGroups(ctx context.Context, g *[]*proto.Group) (err error) DeleteGroup(ctx context.Context, id string) (err error) }