diff --git a/chaoscenter/authentication/pkg/project/repository.go b/chaoscenter/authentication/pkg/project/repository.go index 8f170b8967f..0fd8a0db75a 100644 --- a/chaoscenter/authentication/pkg/project/repository.go +++ b/chaoscenter/authentication/pkg/project/repository.go @@ -60,7 +60,7 @@ func (r repository) GetProjects(query bson.D) ([]*entities.Project, error) { return nil, err } - var projects []*entities.Project + var projects = []*entities.Project{} err = results.All(context.TODO(), &projects) if err != nil { return nil, err @@ -71,7 +71,7 @@ func (r repository) GetProjects(query bson.D) ([]*entities.Project, error) { // GetProjectsByUserID returns a project based on the userID func (r repository) GetProjectsByUserID(request *entities.ListProjectRequest) (*entities.ListProjectResponse, error) { - var projects []*entities.Project + var projects = []*entities.Project{} ctx := context.TODO() // Construct the pipeline @@ -184,7 +184,7 @@ func (r repository) GetProjectStats() ([]*entities.ProjectStats, error) { return nil, err } - var data []*entities.ProjectStats + var data = []*entities.ProjectStats{} for result.Next(context.TODO()) { res := entities.ProjectStats{} if err := result.Decode(&res); err != nil { @@ -425,7 +425,7 @@ func (r repository) GetOwnerProjects(ctx context.Context, userID string) ([]*ent return nil, err } - var projects []*entities.Project + var projects = []*entities.Project{} err = cursor.All(context.TODO(), &projects) if err != nil { return nil, err @@ -447,7 +447,7 @@ func (r repository) GetProjectOwners(projectID string) ([]*entities.Member, erro } // Filter the members to include only the owners - var owners []*entities.Member + var owners = []*entities.Member{} for _, member := range project.Members { if member.Role == entities.RoleOwner && member.Invitation == entities.AcceptedInvitation { owners = append(owners, member) @@ -615,7 +615,7 @@ func (r repository) ListInvitations(userID string, invitationState entities.Invi return nil, err } - var projects []*entities.Project + var projects = []*entities.Project{} err = cursor.All(context.TODO(), &projects) if err != nil { return nil, err diff --git a/chaoscenter/authentication/pkg/session/api_token_repository.go b/chaoscenter/authentication/pkg/session/api_token_repository.go index 7cc28a6962c..b7973bf5d93 100644 --- a/chaoscenter/authentication/pkg/session/api_token_repository.go +++ b/chaoscenter/authentication/pkg/session/api_token_repository.go @@ -23,7 +23,7 @@ func (r repository) CreateApiToken(apiToken *entities.ApiToken) error { // GetApiTokensByUserID returns all the API tokens for a given user func (r repository) GetApiTokensByUserID(userID string) ([]entities.ApiToken, error) { - var apiTokens []entities.ApiToken + var apiTokens = []entities.ApiToken{} query := bson.D{ {Key: "user_id", Value: userID}, } diff --git a/chaoscenter/authentication/pkg/user/repository.go b/chaoscenter/authentication/pkg/user/repository.go index 2782826609c..e6d7fc5df02 100644 --- a/chaoscenter/authentication/pkg/user/repository.go +++ b/chaoscenter/authentication/pkg/user/repository.go @@ -78,7 +78,7 @@ func (r repository) GetUser(uid string) (*entities.User, error) { // GetUsers fetches all the users from the database func (r repository) GetUsers() (*[]entities.User, error) { - var Users []entities.User + var Users = []entities.User{} cursor, err := r.Collection.Find(context.Background(), bson.M{}) if err != nil { return nil, err