josephspurrier / gowebapp

Basic MVC Web Application in Go
MIT License
1.14k stars 197 forks source link

Call parameter in config.json from middleware/controller #36

Closed karfianto closed 6 years ago

karfianto commented 6 years ago

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

karfianto commented 6 years ago

Here's my working solution in acl.go

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