Golang项目中的main包里除main.go外有其他go文件时,采用go run main.go运行项目报错。 解决办法: 在项目根目录下执行: go build ./main 这样就可以生成名为main的可执行文件,运行此文件即可。