dp815292 2015-03-18 11:27
浏览 26
已采纳

错误:最终函数参数必须具有类型

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

  • 写回答

1条回答 默认 最新

  • douzhu7507 2015-03-18 11:33
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题