我正在使用 https://github.com/gin-gonic/gin写一个http服务 但是当我部署它时,它一直在 tcp6 上部署(根据 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")
最佳答案
文档说明
Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router)
您可以使用http.Server
直接启动服务器,就像http
包在ListenAndServe
server := &http.Server{Handler: r}
l, err := net.Listen("tcp4", addr)
if err != nil {
log.Fatal(err)
}
err = server.Serve(l)
// ...
关于go - 监听 TCP4 而不是 TCP6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38592064/