Skip to content

Instantly share code, notes, and snippets.

@TrinhTrungDung
Created March 20, 2020 11:59
Show Gist options
  • Save TrinhTrungDung/6c928121da2331080234c9dae48583d3 to your computer and use it in GitHub Desktop.
Save TrinhTrungDung/6c928121da2331080234c9dae48583d3 to your computer and use it in GitHub Desktop.
Connect to the database created by docker container
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
func main() {
db, err := gorm.Open("postgres", "host=localhost port=5432 user=testuser dbname=testdb password=123456 sslmode=disable")
if err != nil {
fmt.Println(err)
}
defer db.Close()
fmt.Println("Successfully connect to new database")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment