MIkCode
MIkCode

Reputation: 2845

Go error: Final function parameter must have type

I have an issue with my function. I'm getting a

final function parameter must have type

For this method

func (s *BallotaApi) PostUser(c endpoints.Context,userReq Users) (userRes Users, error) {

    c.Debugf("in the PostUser method")

    user := userManger.login(userReq)//return a Users Type 

    return user, nil

I read those threads but I can't figure out where I'm wrong. It looks like I declared everything.

can-you-declare-multiple-variables-at-once-in-go

go-function-declaration-syntax

Upvotes: 2

Views: 1484

Answers (1)

VonC
VonC

Reputation: 1323973

If you are naming your return parameters, you must name all of them

(userRes Users, err error)

That way, return statements can apply.

As mentioned in Function type:

Within a list of parameters or results, the names (IdentifierList) must either all be present or all be absent.

If you try to name one and not the other, as in this example, you will get:

func a() (b int, error) {
    return 0, nil
}
# command-line-arguments
/tmp/sandbox170113103/main.go:9: final function parameter must have type

Dave C reminds us that:

Named returns should normally be limited to helping make better/clearer godoc documentation or when you need to change return values in a deferred closure.
Other than that they should be avoided.

Upvotes: 10

Related Questions