如何禁用Golang未使用的导入错误

如何禁用Golang未使用的导入错误

本文介绍了如何禁用Golang未使用的导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,将未使用的导入视为错误,迫使您删除导入。
我想知道是否存在改变这种行为的一些希望。例如减少它警告。



我发现这个问题非常烦人,使我无法享受Go中的编码。
例如,我正在测试一些代码,禁用段/函数。 lib中的一些函数不再使用(例如fmt,errors,whatever),但是我需要在一些测试后重新启用函数。现在程序不会编译,除非我删除那些导入。几分钟后,我需要重新导入lib。
在开发一个GAE程序时,我一次又一次地做这个过程。



TBH,这是我在编程语言中看到的最愚蠢的东西。
如果它不是GAE中的性能优势,我甚至不会碰Go。

解决方案 var _ = fmt.Printf 技巧在这里很有帮助。


By default Go treat unused import as error forcing you to delete the import.I want to know if there exist some hope to change to this behavior. e.g. reducing it to warning.

I found this problem extremely annoying prevent 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.

TBH, it is the most stupid thing I have even seen in a programming language.If it is not the performance benefit in GAE, I would not even touch Go.

解决方案

The var _ = fmt.Printf trick is helpful here.

这篇关于如何禁用Golang未使用的导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:47