24 lines
422 B
Go
24 lines
422 B
Go
package db
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
var handle *sql.DB
|
|
|
|
func Init(username, password, protocol, address, database string) error {
|
|
var err error
|
|
|
|
handle, err = sql.Open("mysql", username+":"+password+"@"+protocol+"("+address+")/"+database)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to open database connection: %s", err)
|
|
}
|
|
|
|
handle.SetMaxOpenConns(1000)
|
|
|
|
return nil
|
|
}
|