I'm learning golang and for my first task I have started to build a simple website. The problem is that I need to have some globals available, I have learned that it is not wise to send these globals using context, as context should be different for every request. Therefore I have thought about creating a package that will be filled with needed variables in main(). I haven't seen this solution in other projects, so I'm asking if this is wrong? Simple example of config package:
package config
var DB *sql.DB
And the main:
package main
import "project/config"
func main() {
config.DB, err = sql.Open("postgres", conn)
if err != nil {
panic(err)
}
}
Then I would just import the config package and get the variable wherever I need.