summaryrefslogtreecommitdiff
path: root/rddb
diff options
context:
space:
mode:
Diffstat (limited to 'rddb')
-rw-r--r--rddb/rddb.go44
1 files changed, 22 insertions, 22 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go
index efc0f4f..d54d9a4 100644
--- a/rddb/rddb.go
+++ b/rddb/rddb.go
@@ -97,7 +97,7 @@ type getMusicInfoRequest struct {
response chan<- getMusicInfoResult
}
-type RdDb struct {
+type DB struct {
conf *config
dbh *sql.DB
passwordCache map[string]string
@@ -115,7 +115,7 @@ type RdDb struct {
done chan bool
}
-func (db *RdDb) init() (err error) {
+func (db *DB) init() (err error) {
godrv.Register("SET CHARACTER SET utf8;")
dsn := fmt.Sprintf("tcp:%s:3306*%s/%s/%s", db.conf.dbHost, db.conf.dbDb, db.conf.dbUser, db.conf.dbPasswd)
@@ -152,7 +152,7 @@ func (db *RdDb) init() (err error) {
return
}
-func (db *RdDb) getPassword(username string, cached bool) (result getPasswordResult) {
+func (db *DB) getPassword(username string, cached bool) (result getPasswordResult) {
if cached {
result.password = db.passwordCache[username]
}
@@ -170,7 +170,7 @@ func (db *RdDb) getPassword(username string, cached bool) (result getPasswordRes
return
}
-func (db *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) {
+func (db *DB) getGroupOfCart(cart uint) (result getGroupOfCartResult) {
var rows *sql.Rows
if rows, result.err = db.getGroupOfCartStmt.Query(cart, cart); result.err != nil {
return
@@ -200,7 +200,7 @@ func (db *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) {
return
}
-func (db *RdDb) getLogTableName(log string) (logtable string, err error) {
+func (db *DB) getLogTableName(log string) (logtable string, err error) {
logtable = strings.Replace(log, " ", "_", -1) + "_LOG"
if !mysqlTableNameRe.MatchString(logtable) {
return "", fmt.Errorf("the log table name contains illegal charecters: %s", logtable)
@@ -208,7 +208,7 @@ func (db *RdDb) getLogTableName(log string) (logtable string, err error) {
return
}
-func (db *RdDb) getShowCarts(log string, lowCart, highCart int) (carts []uint, err error) {
+func (db *DB) getShowCarts(log string, lowCart, highCart int) (carts []uint, err error) {
var logtable string
if logtable, err = db.getLogTableName(log); err != nil {
return
@@ -230,7 +230,7 @@ func (db *RdDb) getShowCarts(log string, lowCart, highCart int) (carts []uint, e
return
}
-func (db *RdDb) getShowInfo(showid uint) (result getShowInfoResult) {
+func (db *DB) getShowInfo(showid uint) (result getShowInfoResult) {
var macros string
var lowCart, highCart int
result.err = db.getShowInfoStmt.QueryRow(showid).Scan(&result.title, &macros, &result.group, &result.normLvl, &result.trimLvl, &lowCart, &highCart)
@@ -246,7 +246,7 @@ func (db *RdDb) getShowInfo(showid uint) (result getShowInfoResult) {
return
}
-func (db *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) {
+func (db *DB) checkMusicGroup(group string) (result checkMusicGroupResult) {
var cnt int
if result.err = db.checkMusicGroupStmt.QueryRow(group).Scan(&cnt); result.err != nil {
if result.err == sql.ErrNoRows {
@@ -259,7 +259,7 @@ func (db *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) {
return
}
-func (db *RdDb) getMusicInfo(group string) (result getMusicInfoResult) {
+func (db *DB) getMusicInfo(group string) (result getMusicInfoResult) {
result.err = db.getMusicInfoStmt.QueryRow(group).Scan(&result.normLvl, &result.trimLvl)
if result.err != nil {
if result.err == sql.ErrNoRows {
@@ -270,7 +270,7 @@ func (db *RdDb) getMusicInfo(group string) (result getMusicInfoResult) {
return
}
-func (db *RdDb) dispatchRequests() {
+func (db *DB) dispatchRequests() {
defer func() { db.done <- true }()
for {
select {
@@ -293,7 +293,7 @@ func (db *RdDb) dispatchRequests() {
// *********************************************************
// Public Interface
-type RdDbChan struct {
+type DBChan struct {
getPasswordChan chan<- getPasswordRequest
getGroupOfCartChan chan<- getGroupOfCartRequest
getShowInfoChan chan<- getShowInfoRequest
@@ -301,7 +301,7 @@ type RdDbChan struct {
getMusicInfoChan chan<- getMusicInfoRequest
}
-func (db *RdDbChan) GetPassword(username string, cached bool) (string, error) {
+func (db *DBChan) GetPassword(username string, cached bool) (string, error) {
resCh := make(chan getPasswordResult)
req := getPasswordRequest{}
req.username = username
@@ -316,7 +316,7 @@ func (db *RdDbChan) GetPassword(username string, cached bool) (string, error) {
return res.password, nil
}
-func (db *RdDbChan) CheckPassword(username, password string) (bool, error) {
+func (db *DBChan) CheckPassword(username, password string) (bool, error) {
cached := true
for {
@@ -343,7 +343,7 @@ func (db *RdDbChan) CheckPassword(username, password string) (bool, error) {
return false, nil
}
-func (db *RdDbChan) GetGroupOfCart(cart uint) (string, error) {
+func (db *DBChan) GetGroupOfCart(cart uint) (string, error) {
resCh := make(chan getGroupOfCartResult)
req := getGroupOfCartRequest{}
req.cart = cart
@@ -357,7 +357,7 @@ func (db *RdDbChan) GetGroupOfCart(cart uint) (string, error) {
return res.group, nil
}
-func (db *RdDbChan) GetShowInfo(showid uint) (string, int, int, []uint, error) {
+func (db *DBChan) GetShowInfo(showid uint) (string, int, int, []uint, error) {
resCh := make(chan getShowInfoResult)
req := getShowInfoRequest{}
req.showid = showid
@@ -371,7 +371,7 @@ func (db *RdDbChan) GetShowInfo(showid uint) (string, int, int, []uint, error) {
return res.group, res.normLvl, res.trimLvl, res.carts, nil
}
-func (db *RdDbChan) CheckMusicGroup(groupname string) (bool, error) {
+func (db *DBChan) CheckMusicGroup(groupname string) (bool, error) {
resCh := make(chan checkMusicGroupResult)
req := checkMusicGroupRequest{}
req.group = groupname
@@ -385,7 +385,7 @@ func (db *RdDbChan) CheckMusicGroup(groupname string) (bool, error) {
return res.ismusic, nil
}
-func (db *RdDbChan) GetMusicInfo(groupname string) (int, int, error) {
+func (db *DBChan) GetMusicInfo(groupname string) (int, int, error) {
resCh := make(chan getMusicInfoResult)
req := getMusicInfoRequest{}
req.group = groupname
@@ -399,8 +399,8 @@ func (db *RdDbChan) GetMusicInfo(groupname string) (int, int, error) {
return res.normLvl, res.trimLvl, nil
}
-func (db *RdDb) GetInterface() *RdDbChan {
- ch := &RdDbChan{}
+func (db *DB) GetInterface() *DBChan {
+ ch := &DBChan{}
ch.getPasswordChan = db.getPasswordChan
ch.getGroupOfCartChan = db.getGroupOfCartChan
ch.getShowInfoChan = db.getShowInfoChan
@@ -409,7 +409,7 @@ func (db *RdDb) GetInterface() *RdDbChan {
return ch
}
-func (db *RdDb) Cleanup() {
+func (db *DB) Cleanup() {
db.quit <- true
<-db.done
close(db.quit)
@@ -435,8 +435,8 @@ func (db *RdDb) Cleanup() {
}
}
-func NewRdDb(configfile string) (db *RdDb, err error) {
- db = new(RdDb)
+func NewDb(configfile string) (db *DB, err error) {
+ db = new(DB)
if db.conf, err = newConfig(configfile); err != nil {
return
}