未使用的导入错误

未使用的导入错误

By default, Go treats unused import as error, forcing you to delete the import.I want to know if there exists some hope to change to this behavior, e.g. reducing it to warning.I find this problem extremely annoying, preventing me from enjoying coding in Go.For example, I was testing some code, disabling a segment/function. Some functions from a lib is no longer used (e.g. fmt, errors, whatever), but I will need to re-enable the function after a little testing. Now the program won't compile unless I remove those imports, and a few minutes later I need to re-import the lib.I was doing this process again and again when developing a GAE program. 解决方案 Adding an underscore (_) before a package name will ignore the unused import error.Here is an example of how you could use it:import ( "log" "database/sql" _ "github.com/go-sql-driver/mysql")View more at https://golang.org/ref/spec#Import_declarations 这篇关于如何禁用 Golang 未使用的导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 16:47