How to disable Golang unused import error

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"
)

To import a package solely for its side-effects (initialization), use
the blank identifier as explicit package name.

View more at https://golang.org/ref/spec#Import_declarations

Leave a Comment