Home > database >  How to disable Golang unused function error?
How to disable Golang unused function error?

Time:12-03

I'm trying to debug a program by commenting out a function and seeing how this affects the result. BUT commenting out this function means that it is unused which results in Go throwing an "unused function" error. How do I temporarily disable this error so that I can debug my program without having to re-write my entire program just to debug a small part?

I know that unused imports and variables can be ignored (detailed below), but can't find anything about ignoring unused functions.

To disable/ignore the unused import error simply prepend an _ to the package name.

 import (
   "fmt" // how you normally import packages
   _"log" // how you import packages and ignore the unused import error
)

To disable/ignore an unused variable you can re-name the variable _.

myvar, _ := some_function()

But how do you ignore an unused function?

Here's a screenshot of the error message I'm getting.

CodePudding user response:

From your screenshot, it looks like you are using Go Staticcheck (or your IDE is). If you really need to disable this warning for whatever reason, you can follow the Staticcheck documentation. A comment like this should do it:

//lint:ignore U1000 Ignore unused function temporarily for debugging
  • Related