Created
October 27, 2020 11:39
-
-
Save d-fal/7aae6c5b08264b92ebdc9be4c7e98c2b to your computer and use it in GitHub Desktop.
This file contains 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 model | |
import ( | |
"database/sql" | |
"fmt" | |
"time" | |
"github.com/godror/godror" | |
"github.com/godror/godror/dsn" | |
) | |
// DBFunc database function | |
type DBFunc struct { | |
dbConn *sql.DB | |
} | |
//var GlobalDb * DBFunc | |
var ( | |
GlobalDb *DBFunc | |
dbConf conf.DatabaseObject | |
) | |
// DialDB establishes a new connection to db | |
func DialDB() *DBFunc { | |
db := &DBFunc{ | |
dbConn: &sql.DB{}, | |
} | |
conf := getDBConnCredentials() | |
dbConf := godror.ConnectionParams{ | |
CommonParams: dsn.CommonParams{ | |
Username: "user", | |
Password: dsn.NewPassword("secret"), | |
Timezone: time.Local, | |
}, | |
// ConnParams: godror.ConnParams{ | |
// ConnClass: "POOLED", | |
// }, | |
PoolParams: godror.PoolParams{ | |
MinSessions: 0, | |
MaxSessions: 50, | |
SessionIncrement: 1, | |
SessionTimeout: 42 * time.Second, | |
MaxLifeTime: time.Hour, | |
}, | |
} | |
dbConf.ConnectString = "172.30.20.10:1521/testdb" | |
db.dbConn = sql.OpenDB(godror.NewConnector(dbConf)) | |
return db | |
} | |
// GetDBInstance get db instance and checks if instance is going well | |
func GetDBInstance() *DBFunc { | |
if GlobalDb == nil { | |
GlobalDb = DialDB() | |
} | |
return GlobalDb | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment