登录
首页 >  Golang >  Go问答

如何将特定信道路由到空通道

来源:stackoverflow

时间:2024-02-28 10:00:19 326浏览 收藏

一分耕耘,一分收获!既然都打开这篇《如何将特定信道路由到空通道》,就坚持看下去,学下去吧!本文主要会给大家讲到等等知识点,如果大家对本文有好的建议或者看到有不足之处,非常欢迎大家积极提出!在后续文章我会继续更新Golang相关的内容,希望对大家都有所帮助!

问题内容

如果我有一个空的接口通道类型,我只想监视事件,并希望根据需要的流程为其分配特定通道,这在 golang 中可能吗?

myChan := make(chan interface{})
confirms := ch.NotifyPublish(make(chan amqp.Confirmation, 1))
myChan = confirms // (<- cannot use type chan Confirmation in type chan interface{} assignment

解决方案


您可以将通道本身作为空接口传递,然后在另一端解析它。

confirms := ch.NotifyPublish(make(chan amqp.Confirmation, 1))
var mychanpointerpointer interface{}
mychanpointerpointer = confirms
.
.
.
switch mychanpointer := mychanpointerpointer.(type) {
case chan amqp.Confirmation:
    fmt.Println("GOT A CONFIRMATION CHANNEL:", mychanpointer)
}

输出:获得确认通道:0xc42016a000

本篇关于《如何将特定信道路由到空通道》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>