I got my database settings in .env
file. Whenever I write source .env
it doesn't work, I have no clue why, in other apps it works fine. I am getting this error now
`` is not officially supported, running under compatibility mode.
2021/04/15 16:57:03 sql: unknown driver "" (forgotten import?)
exit status 1
My imports:
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
dialect := os.Getenv("DIALECT")
host := os.Getenv("HOST")
dbPort := os.Getenv("DBPORT")
user := os.Getenv("USER")
dbName := os.Getenv("NAME")
password := os.Getenv("PASSWORD")
dbURI := fmt.Sprintf("host=%s user=%s dbname=%s password=%s port=%s", host, user, dbName, password, dbPort)
It runs fine, whenever I provide settings such as dialect := "postgres"
etc. But it won't work with env file, why my app is not finding it?
Folder structure
api/
.env
go.mod
go.sum
main.go