Skip to content

Commit

Permalink
GO-3582: fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
  • Loading branch information
AnastasiaShemyakinskaya committed Aug 19, 2024
1 parent a1f5745 commit 3e1723a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
24 changes: 5 additions & 19 deletions filenode/filenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package filenode

import (
"context"
"encoding/json"
"errors"
"slices"

Expand Down Expand Up @@ -232,33 +231,20 @@ func (fn *fileNode) SpaceInfo(ctx context.Context, spaceId string) (info *filepr
return
}

func (fn *fileNode) BatchAccountInfoToJSON(ctx context.Context, identities []string) (string, error) {
func (fn *fileNode) BatchAccountInfo(ctx context.Context, identities []string) ([]*fileproto.AccountInfoResponse, error) {
accountInfos := make([]*fileproto.AccountInfoResponse, 0, len(identities))
for _, identity := range identities {
accountInfo, err := fn.accountInfo(ctx, identity)
if err != nil {
return "", err
return nil, err
}
accountInfos = append(accountInfos, accountInfo)
}

accountInfosJson, err := json.MarshalIndent(accountInfos, "", " ")
if err != nil {
return "", err
}
return string(accountInfosJson), nil
return accountInfos, nil
}

func (fn *fileNode) AccountInfoToJSON(ctx context.Context, identity string) (string, error) {
accountInfo, err := fn.accountInfo(ctx, identity)
if err != nil {
return "", err
}
accountInfoJson, err := json.MarshalIndent(accountInfo, "", " ")
if err != nil {
return "", err
}
return string(accountInfoJson), nil
func (fn *fileNode) AccountInfo(ctx context.Context, identity string) (*fileproto.AccountInfoResponse, error) {
return fn.accountInfo(ctx, identity)
}

func (fn *fileNode) AccountInfoCtx(ctx context.Context) (info *fileproto.AccountInfoResponse, err error) {
Expand Down
9 changes: 5 additions & 4 deletions stat/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"net/http"

"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/commonfile/fileproto"
)

const CName = "stat.identity"

type accountInfoProvider interface {
AccountInfoToJSON(ctx context.Context, identity string) (string, error)
BatchAccountInfoToJSON(ctx context.Context, identities []string) (string, error)
AccountInfo(ctx context.Context, identity string) (*fileproto.AccountInfoResponse, error)
BatchAccountInfo(ctx context.Context, identities []string) ([]*fileproto.AccountInfoResponse, error)
}

type Stat interface {
Expand Down Expand Up @@ -43,7 +44,7 @@ func (i *identityStat) Run(ctx context.Context) (err error) {
http.Error(writer, "identity is empty", http.StatusBadRequest)
return
}
accountInfo, err := i.accountInfoProvider.AccountInfoToJSON(request.Context(), identity)
accountInfo, err := i.accountInfoProvider.AccountInfo(request.Context(), identity)
if err != nil {
http.Error(writer, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -64,7 +65,7 @@ func (i *identityStat) Run(ctx context.Context) (err error) {
http.Error(writer, "invalid JSON", http.StatusBadRequest)
return
}
accountInfos, err := i.accountInfoProvider.BatchAccountInfoToJSON(request.Context(), data.Ids)
accountInfos, err := i.accountInfoProvider.BatchAccountInfo(request.Context(), data.Ids)
if err != nil {
http.Error(writer, err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit 3e1723a

Please sign in to comment.