Skip to content

Instantly share code, notes, and snippets.

@darmawan01
Created May 16, 2020 14:09
Show Gist options
  • Save darmawan01/b805856fc5d3b06f294e78288222c013 to your computer and use it in GitHub Desktop.
Save darmawan01/b805856fc5d3b06f294e78288222c013 to your computer and use it in GitHub Desktop.
Setup Postgres With Gorm
package db
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
// InitPostgres func
func InitGormPostgres() (conn *gorm.DB) {
conf := getConfig()
var err error
conn, err = gorm.Open("postgres",
fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
conf.Host,
conf.Port,
conf.User,
conf.Password,
conf.DbName,
),
)
if err != nil {
panic(err)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment