mirror of https://github.com/statping/statping
upgrades - plugins
parent
801637254f
commit
e265765c75
|
@ -47,6 +47,7 @@ before_install:
|
|||
- if [[ "$TRAVIS_BRANCH" == "master" ]]; then travis_wait 30 docker pull karalabe/xgo-latest; fi
|
||||
|
||||
before_script:
|
||||
- psql -c 'create database travis_ci_test;' -U postgres
|
||||
- go get github.com/stretchr/testify/assert
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
- go get github.com/rendon/testcli
|
||||
|
|
22
database.go
22
database.go
|
@ -5,17 +5,33 @@ import (
|
|||
"fmt"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func DbConnection() error {
|
||||
func DbConnection(dbType string) error {
|
||||
var err error
|
||||
dbinfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", configs.Host, configs.Port, configs.User, configs.Password, configs.Database)
|
||||
db, err = sql.Open("postgres", dbinfo)
|
||||
var dbInfo string
|
||||
if dbType=="sqlite3" {
|
||||
dbInfo = "./statup.db"
|
||||
} else if dbType=="mysql" {
|
||||
dbInfo = fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8", configs.User, configs.Password, configs.Host, configs.Port, configs.Database)
|
||||
} else {
|
||||
dbInfo = fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", configs.Host, configs.Port, configs.User, configs.Password, configs.Database)
|
||||
}
|
||||
db, err = sql.Open(dbType, dbInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//stmt, err := db.Prepare("CREATE database statup;")
|
||||
//if err != nil {
|
||||
// panic(err)
|
||||
//}
|
||||
//stmt.Exec()
|
||||
|
||||
plugin.SetDatabase(db)
|
||||
return err
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -247,7 +247,7 @@ func main() {
|
|||
|
||||
func mainProcess() {
|
||||
var err error
|
||||
err = DbConnection()
|
||||
err = DbConnection(configs.Connection)
|
||||
if err != nil {
|
||||
throw(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue