From 73b8f7618514f0e8204c7eedb87cfbe7cde8a980 Mon Sep 17 00:00:00 2001 From: AndrewZuo01 Date: Tue, 12 Dec 2023 16:59:23 +0800 Subject: [PATCH] update user command --- internal/rpc/user/user.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index a51cb86a6..51e277e8c 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -375,8 +375,8 @@ func (s *userServer) ProcessUserCommandGet(ctx context.Context, req *pbuser.Proc return nil, err } - // Create a slice to store CommandInfoResp - commandInfoSlice := []*pbuser.CommandInfoResp{} + // Initialize commandInfoSlice as an empty slice + commandInfoSlice := make([]*pbuser.CommandInfoResp, 0, len(commands)) for _, v := range commands { commandInfoSlice = append(commandInfoSlice, &pbuser.CommandInfoResp{ @@ -386,6 +386,6 @@ func (s *userServer) ProcessUserCommandGet(ctx context.Context, req *pbuser.Proc }) } - // Return the new slice + // Return the response with the slice, which is empty but not nil if there are no commands return &pbuser.ProcessUserCommandGetResp{KVArray: commandInfoSlice}, nil }