E
E
Eugene2020-01-17 16:20:05
go
Eugene, 2020-01-17 16:20:05

How to return result or error?

I have a function that can return a struct or an error. But when I write return nil, err, I get an error
func Start() (RestResponse, error) {

if err != nil {
  return nil, err
}


cannot convert nil (untyped nil value) to RestResponse

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2020-01-17
@you_are_enot

To return nil, the type must be a reference type,
or you can return an error like this:

if err != nil {
  return RestResponse{}, err
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question