MySQL storage configuration
This commit is contained in:
parent
259043573c
commit
307d096865
|
@ -25,15 +25,16 @@ const (
|
||||||
loadStateQuery = "select repo, sha1, ts from state"
|
loadStateQuery = "select repo, sha1, ts from state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New() *MysqlStorage {
|
func New(host, user, pass, db string) *MysqlStorage {
|
||||||
var (
|
var (
|
||||||
s = &MysqlStorage{
|
s = &MysqlStorage{
|
||||||
state: map[string]*steward.State{},
|
state: map[string]*steward.State{},
|
||||||
}
|
}
|
||||||
err error
|
err error
|
||||||
|
databaseURI = makeDatabaseURI(host, user, pass, db)
|
||||||
)
|
)
|
||||||
|
|
||||||
if s.db, err = sql.Open("mysql", "root@/steward?parseTime=true"); err != nil {
|
if s.db, err = sql.Open("mysql", databaseURI); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if s.importStmt, err = s.db.Prepare(importQuery); err != nil {
|
if s.importStmt, err = s.db.Prepare(importQuery); err != nil {
|
||||||
|
@ -94,3 +95,25 @@ func (ms *MysqlStorage) loadGlobalState() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeDatabaseURI(host, user, pass, db string) string {
|
||||||
|
var (
|
||||||
|
databaseURI string
|
||||||
|
)
|
||||||
|
|
||||||
|
if user != "" {
|
||||||
|
databaseURI += user
|
||||||
|
}
|
||||||
|
if pass != "" {
|
||||||
|
databaseURI += ":" + pass
|
||||||
|
}
|
||||||
|
if user != "" {
|
||||||
|
databaseURI += "@"
|
||||||
|
}
|
||||||
|
if host != "" {
|
||||||
|
databaseURI += host
|
||||||
|
}
|
||||||
|
databaseURI += "/" + db + "?parseTime=true"
|
||||||
|
|
||||||
|
return databaseURI
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue