go静态检查_安全检查

1 gosec - Golang Security Checker

Inspects source code for security problems by scanning the Go AST.

Selecting rules

By default, gosec will run all rules against the supplied file paths. It is however possible to select a subset of rules to run via the -include= flag, or to specify a set of rules to explicitly exclude using the -exclude=flag.

# Run a specific set of rules
$ gosec -include=G101,G203,G401 ./...

# Run everything except for rule G303
$ gosec -exclude=G303 ./...

Excluding test files and folders  排除测试文件和文件夹

使用

我们可以将Gosec配置为仅运行某个规则子集,如排除某些文件路径,生成不同格式的报告等。在默认情况下,Gosec将对提供的输入文件运行所有规则。要从当前目录递归扫描,你可以提供’./…’ 作为输入参数。

选择规则

默认情况下,gosec将针对提供的文件路径运行所有规则。但如果你要指定运行某个规则,则可以使用 ‘-include=’ 参数,或者你也可以使用 ‘-exclude=’来排除那些你不想运行的规则。

注释代码

与所有自动检测工具一样,gosec也会出现误报的情况。如果gosec报告已手动验证为安全的,则可以使用“#nosec”来注释代码。

注释将导致gosec停止处理AST中的任何其他节点,因此可以应用于整个块或应用于单个表达式中。

在某些情况下,你可能还需要重新访问已使用#nosec注释的位置。那么你可以执行以下命令来运行扫描程序以及忽略#nosec注释:

$ gosec -nosec=true ./...

go test

go test 默认执行当前目录下以xxx_test.go的测试文件。
go test -v 可以看到详细的输出信息。
go test -v xxx_test.go 指定测试单个文件,但是该文件中如果调用了其它文件中的模块会报错。

指定某个测试函数运行:
go test -v -test.run Testxxx
注意: 该测试会测试包含该函数名的所有函数,即如果待测试的函数名是TestSyncResourceQuota,那么指令go test -v -test.run TestSyncResourceQuota会测试包含该函数名的所有函数(比如下面的TestSyncResourceQuotaSpecChange、TestSyncResourceQuotaSpecHardChange等函数)

执行所有模块的测试,方式是以三个点替代具体的模块路径:

$ go test -v ...

 收集覆盖率数据


go test -v -coverprofile=cover.out github.com/pirlo-san/let-us-go/bitvector/

生成html格式的覆盖率报告

go tool cover -html=cover.out -o coverage.html

 
原文地址:https://www.cnblogs.com/pythonwork/p/13087712.html