#Cannot initialize 1 variables with 2 values

12 messages · Page 1 of 1 (latest)

twin sundial
#

Hello, I'm a bit confused why this line is causing issues. I did add an error to be returned as well.

eulaService := services.NewEulaService(mongoDB)

I've tried adding error in different spots with no luck, example:

eulaService := services.NewEulaService(mongoDB), error

#

This is the function it's referring to: // NewEulaService creates a new EulaService interface func NewEulaService(database nosql.Database) (Eulas, error) { if database == nil { return nil, errors.New("nil database") } return &eulasService{ database: database, }, nil }

halcyon totem
#

NewEulaService returns 2 values (Eulas, error)
you tried to assign the output of 2 values, into 1 variable

#

if you intend to ignore the second one
you need to use
value, _ := someFunc()

#

_ will assign the second value to a blank variable

#

therefore discarding it

twin sundial
#

Interesting!

#

I think I got it!

#

So it's looking for value and then something else.

#

That makes sense.

#

eulaService, _ := services.NewEulaService(mongoDB)

#

did the trick