Go error:最终函数参数必须有类型

MIk*_*ode 2 go

我的功能有问题.我得到了一个

final function parameter must have type
Run Code Online (Sandbox Code Playgroud)

对于这种方法

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
Run Code Online (Sandbox Code Playgroud)

我读了那些线程,但我无法弄清楚我错在哪里.看起来我宣布了一切.

可任您申报,多变量 - 在 - 一次在去

去功能声明的语法

Von*_*onC 10

如果你命名你的回报参数,你必须命名所有的

(userRes Users, err error)
Run Code Online (Sandbox Code Playgroud)

这样,return语句就可以应用了.

功能类型中所述:

在参数或结果列表中,names(IdentifierList)必须全部存在或全部不存在.

如果您尝试命名一个而不是另一个,如本示例所示,您将获得:

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

Dave C提醒我们:

命名返回通常应限于帮助制作更好/更清晰的godoc文档,或者当您需要在延迟闭包中更改返回值时.
除此之外,他们应该避免.