无法通过127.0.0.1访问gin的第一个实例

最近学习gin框架,入门第一个gin框架实例就受挫。

func main() {
	// 创建一个默认的路由引擎
	r := gin.Default()
	// GET:请求方式;/hello:请求的路径
	// 当客户端以GET方法请求/hello路径时,会执行后面的匿名函数
	r.GET("/hello", func(c *gin.Context) {
		// c.JSON:返回JSON格式的数据
		c.JSON(200, gin.H{
			"message": "Hello world!",
		})
	})
	// 启动HTTP服务,默认在0.0.0.0:8080启动服务
	r.Run()
}

教程说通过127.0.0.1:8080/hello即可访问,但是我试过很多次都无法访问。但是通过localhost:8080/hello则可以访问。请教大佬,出了什么问题

// 不谢
r.Run(":8089") // http://127.0.0.1:8089/ping

 

你看下电脑hosts文件中的有没有这句:

#    127.0.0.1       localhost