go - Golang 中是否有任何命令行来检查我的 go 源代码的语法错误并将错误写入文件?
问题描述
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 '}'
推荐阅读
- linux - 临时屏幕输出会话存储在哪里
- c# - 根据 id 获取绑定对象
- java - 从不同的类调用时,Java repaint() 不起作用
- android - 更改按钮颜色会导致按钮变大
- apache-spark - 如何使用 YARN 客户端模式在 Jupyter 中以交互方式运行 Pyspark?
- sorting - 将 jinja 列表中的值四舍五入
- android - 在从活动移动到片段时实现抽象方法
- c# - Throttling connections on 429 errors in WebClient mechanism, best practice?
- mysql - mysql 只有在前 12 条最新记录中才选择用户
- r - local image in shiny app without img(src())?