I have two different files: (1) /common/handler.go and (2) main.go.
In the (/common/handler.go) file, I have declared
var db *sql.DB
var err error
as global variables (at the top level, below import). Now, I want to use these two variables in my main.go file because I have this line of code in my main() function:
db, err = sql.Open("mysql","username:password@tcp(127.0.0.1:3306)/test123")
What should I do in order for Go to understand that I was referring to that db and err variables? Am I even doing this the right way? If not, please let me know the best solution.
The reason I split into these two files because I want to make the code cleaner.
Basically, main() in main.go contains
router := mux.NewRouter()
router.HandleFunc("/", common.login)
....
and handler.go contains all the messy stuff.
Thanks,