package main
import "fmt"
func plus(a int, b int) int {
return a + b
}
}
func plusPlus(a, b, c int) int {
return a + b + c
}
func main() {
res := plus(1, 2)
fmt.Println("1+2 =", res)
res = plusPlus(1, 2, 3)
fmt.Println("1+2+3 =", res)
}
这是我的 Go 源代码。
gofmt -e my_file.go
正在运行,但我无法将错误写入文本文件。
最佳答案
gofmt
会将错误输出到标准错误。您可以简单地将 gofmt
的标准错误流重定向到 unix 系统上的文件,如下所示:
gofmt -e my_file.go 2>a.txt
检查它:
more a.txt
输出:
my_file.go:8:1: expected declaration, found '}'
关于go - Golang 中是否有任何命令行来检查我的 go 源代码的语法错误并将错误写入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51626813/