Skip to content

Commit

Permalink
refactor: Changed Keys to be type KeyList instead of []Key
Browse files Browse the repository at this point in the history
  • Loading branch information
andrix10 authored and janaakhterov committed Jan 22, 2021
1 parent a20c709 commit 096a68d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
20 changes: 6 additions & 14 deletions file_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ type FileInfo struct {
Size int64
ExpirationTime time.Time
IsDeleted bool
Keys []Key
Keys KeyList
}

func newFileInfo(fileID FileID, size int64, expirationTime time.Time, isDeleted bool, keys []Key) FileInfo {
func newFileInfo(fileID FileID, size int64, expirationTime time.Time, isDeleted bool, keys KeyList) FileInfo {
return FileInfo{
FileID: fileID,
Size: size,
Expand All @@ -24,14 +24,13 @@ func newFileInfo(fileID FileID, size int64, expirationTime time.Time, isDeleted
}

func fileInfoFromProtobuf(fileInfo *proto.FileGetInfoResponse_FileInfo) (FileInfo, error) {
var keys []Key
var keys KeyList
var err error
if fileInfo.Keys != nil {
keyList, err := keyListFromProtobuf(fileInfo.Keys)
keys, err = keyListFromProtobuf(fileInfo.Keys)
if err != nil {
return FileInfo{}, err
}

keys = keyList.keys
}

return FileInfo{
Expand All @@ -44,11 +43,6 @@ func fileInfoFromProtobuf(fileInfo *proto.FileGetInfoResponse_FileInfo) (FileInf
}

func (fileInfo *FileInfo) toProtobuf() *proto.FileGetInfoResponse_FileInfo {
var keys = make([]*proto.Key, 0)
for _, key := range fileInfo.Keys {
keys = append(keys, key.toProtoKey())
}

return &proto.FileGetInfoResponse_FileInfo{
FileID: fileInfo.FileID.toProtobuf(),
Size: fileInfo.Size,
Expand All @@ -57,8 +51,6 @@ func (fileInfo *FileInfo) toProtobuf() *proto.FileGetInfoResponse_FileInfo {
Nanos: int32(fileInfo.ExpirationTime.Nanosecond()),
},
Deleted: fileInfo.IsDeleted,
Keys: &proto.KeyList{
Keys: keys,
},
Keys: fileInfo.Keys.toProtoKeyList(),
}
}
1 change: 1 addition & 0 deletions file_info_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func Test_FileInfo_Transaction(t *testing.T) {
assert.Equal(t, *fileID, info.FileID)
assert.Equal(t, info.Size, int64(12))
assert.False(t, info.IsDeleted)
assert.NotNil(t, info.Keys)

resp, err = NewFileDeleteTransaction().
SetFileID(*fileID).
Expand Down

0 comments on commit 096a68d

Please sign in to comment.