package postgres import ( "fmt" "git.tek.govt.hu/dowerx/chat/server/config" "git.tek.govt.hu/dowerx/chat/server/util" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" ) var db *sqlx.DB func getDatabase() (*sqlx.DB, *util.ChatError) { if db == nil { cfg := config.GetConfig() newDB, err := sqlx.Connect("postgres", fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", cfg.Database.Host, cfg.Database.Port, cfg.Database.User, cfg.Database.Password, cfg.Database.DBname)) if err != nil { return nil, util.MakeError(err, util.DATABASE_CONNECTION_FAULT) } db = newDB } return db, nil }