Go start error: Panic: runtime error: invalid memory address or nil pointer reference

For more details, see blog post:
a pit about Golang variable scope

remove the colon from DB, err := gorm.open:

the original understanding was that golang would define the new variable err, DB was the global variable originally defined. But the reality is that for a variable defined with :=, if the new variable DB is not in scope with the same name as the defined variable (in this case, the global variable DB), then Golang defines the new variable DB to cover up the global variable DB, which is the real cause of the problem.

Read More: