登录
首页 >  Golang >  Go问答

Gin-gonic 错误:监听 tcp:查找地址:没有这样的主机

来源:stackoverflow

时间:2024-04-02 11:51:42 172浏览 收藏

golang学习网今天将给大家带来《Gin-gonic 错误:监听 tcp:查找地址:没有这样的主机》,感兴趣的朋友请继续看下去吧!以下内容将会涉及到等等知识点,如果你是正在学习Golang或者已经是大佬级别了,都非常欢迎也希望大家都能给我建议评论哈~希望能帮助到大家!

问题内容

machine : debian 10 running on windows 10 - hypervisor 
go ver  : go1.14.4
gin-gonic version : v1.6.3

运行程序时出现以下错误!。尝试了在网络中找到的许多解决方案,但没有运气(这些与 gin-gonic 没有直接关系)

$ go run main.go
[gin-debug] [warning] creating an engine instance with the logger and recovery middleware already attached.

[gin-debug] [warning] running in "debug" mode. switch to "release" mode in production.
 - using env:   export gin_mode=release
 - using code:  gin.setmode(gin.releasemode)

[gin-debug] listening and serving http on addr:8080
[gin-debug] [error] listen tcp: lookup addr on 192.168.43.1:53: no such host
calling okay!!!

main程序调用application.go中的函数startapplicaton

$ cat app/application.go
    package app

    import(  "fmt"
            "github.com/gin-gonic/gin"
    )

var (
        router = gin.default()
)

//startapplicaiton will call from main
func startapplicaton() {
        mapurls()
        router.run("addr:8080")
        fmt.println("calling okay!!!")
}

包括/etc/resolve.conf/etc/hosts文件供参考

$cat /etc/resolv.conf
nameserver 192.168.43.1
nameserver 8.8.8.8


$ cat /etc/hosts
127.0.0.1       localhost
127.0.1.1       debian
192.168.43.1    wifirtr #addded to check

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

解决方案


router.Run("addr:8080") 更改为 router.Run(":8081") 解决了我的问题!!, 我仍然不确定为什么它解决了我的问题(需要稍后挖掘)

编辑:后来发现addr部分不在代码中,它是IDE显示的帮助文本。我在遵循在线教程时误解了。

到这里,我们也就讲完了《Gin-gonic 错误:监听 tcp:查找地址:没有这样的主机》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

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