O
O
Oleg Voitenko2018-04-20 13:29:42
go
Oleg Voitenko, 2018-04-20 13:29:42

How to correctly read a function in GO?

I am just starting to learn the GO language. Help read the function in human language.

func (p *myDb) SelectUsers() ([]*model.User, error) {
  user := make([]*model.User, 0)
  if err := p.sqlSelectUsers.Select(&user); err != nil {
    return nil, err
  }
  return user, nil
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Papa, 2018-04-20
@OliverV

user := make([]*model.User, 0)
a slice receiver is declared for the *model.User array

if err := p.sqlSelectUsers.Select(&user); err != nil {
    return nil, err
}

a query is made to the database. if an error is returned, we return nil and an error;
otherwise, we return the destination slice with the result from the database and nil

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question