mirror of
https://github.com/go-shiori/shiori.git
synced 2025-01-16 04:48:30 +08:00
Make MySQL address changeable #156
This commit is contained in:
parent
5b44801b87
commit
df98c281d3
2 changed files with 5 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
fp "path/filepath"
|
||||
|
||||
|
@ -105,8 +106,10 @@ func openDatabase() (database.DB, error) {
|
|||
user, _ := os.LookupEnv("SHIORI_MYSQL_USER")
|
||||
password, _ := os.LookupEnv("SHIORI_MYSQL_PASS")
|
||||
dbName, _ := os.LookupEnv("SHIORI_MYSQL_NAME")
|
||||
dbAddress, _ := os.LookupEnv("SHIORI_MYSQL_ADDRESS")
|
||||
|
||||
return database.OpenMySQLDatabase(user, password, dbName)
|
||||
connString := fmt.Sprintf("%s:%s@%s/%s", user, password, dbAddress, dbName)
|
||||
return database.OpenMySQLDatabase(connString)
|
||||
}
|
||||
|
||||
// If not, just uses SQLite
|
||||
|
|
|
@ -18,9 +18,8 @@ type MySQLDatabase struct {
|
|||
}
|
||||
|
||||
// OpenMySQLDatabase creates and opens connection to a MySQL Database.
|
||||
func OpenMySQLDatabase(username, password, dbName string) (mysqlDB *MySQLDatabase, err error) {
|
||||
func OpenMySQLDatabase(connString string) (mysqlDB *MySQLDatabase, err error) {
|
||||
// Open database and start transaction
|
||||
connString := fmt.Sprintf("%s:%s@/%s", username, password, dbName)
|
||||
db := sqlx.MustConnect("mysql", connString)
|
||||
db.SetMaxOpenConns(100)
|
||||
db.SetConnMaxLifetime(time.Second) // in case mysql client has longer timeout (driver issue #674)
|
||||
|
|
Loading…
Reference in a new issue