[GIN-debug] [ERROR] listen tcp: address 8080: missing port in address

学习Golang_gin框架的第一天

遇到一下报错 : 

[GIN-debug] [ERROR] listen tcp: address 8080: missing port in address
 

错误代码 : 

package main

import "github.com/gin-gonic/gin"

func main() {
	router := gin.Default()

	router.GET("/index", func(context *gin.Context) {
		context.String(200, "Hello World")
	})

	router.Run("8080")
}

报错原因 : 粗心

改错 : 在8080前面加上 : 符号

代码变为 : 

package main

import "github.com/gin-gonic/gin"

func main() {
	router := gin.Default()

	router.GET("/index", func(context *gin.Context) {
		context.String(200, "Hello World")
	})

	router.Run(":8080")
}

希望大家写代码要细心!!!

猜你喜欢

转载自blog.csdn.net/ros275229/article/details/132198817