【发布时间】:2023-01-18 11:02:23
【问题描述】:
我用gin测试时,端口无法正常启动: [错误] listen tcp :8080: bind: 地址已被使用 我用route修改端口的时候还是显示使用8080端口
func main() {
//r := gin.Default()
//r.GET("/ping", func(c *gin.Context) {
// c.JSON(http.StatusOK, gin.H{
// "message": "pong",
// })
//})
router := gin.Default()
router.GET("/hi", func(context *gin.Context) {
context.String(http.StatusOK, "Hello world!")
})
err := router.Run()
if err != nil {
panic("[Error] failed to start Gin server due to: " + err.Error())
return
}
router.Run(":9888")
//r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
我应该如何修改它