Go Underscore
Underscore in import
When importing a package, all init functions under that package will be executed. Therefore, if we only want to execute the init functions without importing the entire package, we can use import _ "package/path". This is done solely for the purpose of invoking the init functions, and as a result, we cannot use the package name to call other functions within the package.
import "database/sql"
import _ "github.com/go-sql-driver/mysql"
The second import statement does not directly use the mysql package; it merely executes the init function of this package to register the mysql driver with the sql package. After that, the program can use the sql package to access the mysql database.
Underscore in Variable Assignment
As a placeholder, it indicates that a value was intended to be assigned to a variable, but currently, that value is not needed. So, the value is assigned to the underscore, meaning it is discarded (ignore this variable).
//the conventional way of writing
f, err := os.Open("trace.log")
//ignore the err variable If the error value returned is not needed at this moment
f, _ := os.Open("trace.log")
Take a break
πππ γBTTH Year EP99γXiao Yan rescued Nalan Yanran and escorted her all the way...