Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slice initialization to avoid null response #4931

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions chaoscenter/authentication/pkg/project/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/authentication/pkg/user/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading