Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

im working on a Golang project ,and connecting its database using ORM ..and getting this error .can anyone helpme out

open .env: The system cannot find the file specified.conn &{ 0 0xc00017e480 false 0 {0xc00022c9b0} {{0 0} {} map[] 0} 0xc0000b0dc0 0x1062880 0xc000260600 false}dial tcp :0: connectex: The requested address is not valid in its context. sql: database is closed


 e := godotenv.Load()
if e != nil {
    fmt.Print(e,)
}
gin.SetMode(gin.ReleaseMode)
username := os.Getenv("db_user")
password := os.Getenv("db_pass")
dbName := os.Getenv("db_name")
dbHost := os.Getenv("db_host")
dbPort := os.Getenv("db_port")

conn, err := gorm.Open("mysql",   username+":"+password+"@tcp("+dbHost+":"+dbPort+")/"+dbName+"?charset=utf8&parseTime=True&loc=Asia%2FKolkata")

fmt.Println("conn", conn)
if err != nil {
    fmt.Print(err)
}
db = conn
db.LogMode(true)

db.Debug().AutoMigrate(&User{})

fmt.Println("hererer")
fmt.Println(db.AutoMigrate(&User{}))
} 

Comments