dsjpqpdm620596 2019-01-07 08:31
浏览 41

函数末尾缺少返回

I have a getQueue() function to create a connection and channel for my Go client to a RabbitMQ instance. I have this code for the aforementioned function:

func getQueue() (*amqp.Connection, *amqp.Channel, *amqp.Queue) {
    conn, err := amqp.Dial("amqp://ayman@localhost:5672")
    fallOnError(err, "Fail to connect")
    ch, err := conn.Channel()
    fallOnError(err, "Fail to open channel")
    q, err := ch.QueueDeclare("hello",
        false, //durable
        false, //autoDelete
        false, //exclusive
        false, //noWait
        nil)   //args
    fallOnError(err, "Fail to delare a queue")

} 

I am getting this error Missing return at end of function for the same. I tried using return keyboard at the end of the function, but then I get this error:

not enough arguments to return
have ()
want (*amqp.Connection, *amqp.Channel, *amqp.Queue)

The source video I was referring did not have any such issues. I am using Ubuntu machine with Go version go1.11.4 linux/amd64. I am using Atom editor with go-lang tools package installed.

EDIT The solution is that I needed 3 parameters to return return conn,ch,&q solved my issue.

  • 写回答

2条回答 默认 最新

  • douweng9427 2019-01-07 08:38
    关注

    the (*amqp.Connection, *amqp.Channel, *amqp.Queue) part of your code says your function returns 3 things, but you don't return anything that is why you get the error. Try adding

    return conn, ch, q
    

    to your code that should solve the problem

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器