Reformat responses

This commit is contained in:
Benedikt Kulmann
2020-10-23 16:30:23 +02:00
parent 16a74c8a7e
commit bf5a960714
5 changed files with 20 additions and 32 deletions
+2 -2
View File
@@ -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
},
}
+8 -12
View File
@@ -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
}
+4 -4
View File
@@ -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
}
+4 -4
View File
@@ -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
})
}
+2 -10
View File
@@ -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)
}