Created
May 16, 2020 14:09
-
-
Save darmawan01/b805856fc5d3b06f294e78288222c013 to your computer and use it in GitHub Desktop.
Setup Postgres With Gorm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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