josephspurrier/gowebapp

Call parameter in config.json from middleware/controller

Closed this issue · 1 comments

Hi Joseph,
I have a middleware containing this line of code

a := gormadapter.NewAdapter("mysql", "testuser:testpass@tcp(127.0.0.1:3306)/gowebapp", true) // Your driver and data source.

How can I replace this hardcoded connection string to use config in config.json

		"MySQL": {
			"Username": "testuser",
			"Password": "testpass",
			"Name": "gowebapp",
			"Hostname": "127.0.0.1",
			"Port": 3306,

Thanks

Here's my working solution
in acl.go

conn := database.ReadConfig().MySQL
		dsn := database.DSN(conn)
		a := gormadapter.NewAdapter("mysql", dsn, true)