去lang(go-gin)听TCP4而不是TCP6 [英] go lang (go-gin) listen on TCP4 not TCP6
本文介绍了去lang(go-gin)听TCP4而不是TCP6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 https://github.com/gin-gonic/gin 撰写一个http服务
但是当我部署它时,它会一直在tcp6上部署(根据netstat)
r:= gin.Default()
//这些都不起作用,它一直列在tcp6
r.Run(:8080)
r.Run(*:8080)上
r.Run(0.0.0.0:8080)
解决方案文档状态
$ b
运行将路由器连接到http.Server,并开始监听和提供HTTP请求。这是http.ListenAndServe(addr,router)的一个快捷方式
您可以直接使用 http.Server
与 http
包在 ListenAndServe
$ b
server:=& http.Server {Handler:r}
l,err:= net.Listen(tcp4,addr)
if err!= nil {
log.Fatal(err)
}
err = server.Serve(l)
// ...
I am using https://github.com/gin-gonic/gin to write an http service But when I deploy it, it keeps deploying on tcp6(according to netstat)
r := gin.Default()
//none of these are working , It keeps being listed on tcp6
r.Run(":8080")
r.Run("*:8080")
r.Run("0.0.0.0:8080")
解决方案
The documentation states
Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router)
You can start the server directly using an http.Server
the same way the http
package does in ListenAndServe
server := &http.Server{Handler: r}
l, err := net.Listen("tcp4", addr)
if err != nil {
log.Fatal(err)
}
err = server.Serve(l)
// ...
这篇关于去lang(go-gin)听TCP4而不是TCP6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文