summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport/rddb.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-31 09:46:40 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-31 09:46:40 (GMT)
commit0ef8fcb03fc4f51b8bc6b1a24f2e964b6a03d50c (patch)
treed065a87002893b693e17f2fe503a6f9631564c2b /src/helsinki.at/rhimport/rddb.go
parent620d1b76807f6ecffda54347db7b58107d03c2a5 (diff)
improved coding style
Diffstat (limited to 'src/helsinki.at/rhimport/rddb.go')
-rw-r--r--src/helsinki.at/rhimport/rddb.go98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/helsinki.at/rhimport/rddb.go b/src/helsinki.at/rhimport/rddb.go
index 8bec3c0..12bdba3 100644
--- a/src/helsinki.at/rhimport/rddb.go
+++ b/src/helsinki.at/rhimport/rddb.go
@@ -63,12 +63,12 @@ type getGroupOfCartRequest struct {
}
type getShowInfoResult struct {
- title string
- group string
- carts []uint
- norm_lvl int
- trim_lvl int
- err error
+ title string
+ group string
+ carts []uint
+ normLvl int
+ trimLvl int
+ err error
}
type getShowInfoRequest struct {
@@ -87,9 +87,9 @@ type checkMusicGroupRequest struct {
}
type getMusicInfoResult struct {
- norm_lvl int
- trim_lvl int
- err error
+ normLvl int
+ trimLvl int
+ err error
}
type getMusicInfoRequest struct {
@@ -99,7 +99,7 @@ type getMusicInfoRequest struct {
type RdDb struct {
dbh *sql.DB
- password_cache map[string]string
+ passwordCache map[string]string
getPasswordChan chan getPasswordRequest
getPasswordStmt *sql.Stmt
getGroupOfCartChan chan getGroupOfCartRequest
@@ -117,7 +117,7 @@ type RdDb struct {
func (self *RdDb) init(conf *Config) (err error) {
godrv.Register("SET CHARACTER SET utf8;")
- dsn := fmt.Sprintf("tcp:%s:3306*%s/%s/%s", conf.db_host, conf.db_db, conf.db_user, conf.db_passwd)
+ dsn := fmt.Sprintf("tcp:%s:3306*%s/%s/%s", conf.dbHost, conf.dbDb, conf.dbUser, conf.dbPasswd)
if self.dbh, err = sql.Open("mymysql", dsn); err != nil {
return
}
@@ -153,7 +153,7 @@ func (self *RdDb) init(conf *Config) (err error) {
func (self *RdDb) getPassword(username string, cached bool) (result getPasswordResult) {
if cached {
- result.password = self.password_cache[username]
+ result.password = self.passwordCache[username]
}
if result.password == "" {
@@ -163,7 +163,7 @@ func (self *RdDb) getPassword(username string, cached bool) (result getPasswordR
}
return
}
- self.password_cache[username] = result.password
+ self.passwordCache[username] = result.password
}
return
@@ -175,18 +175,18 @@ func (self *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) {
return
}
defer rows.Close()
- size_min := ^uint(0)
+ sizeMin := ^uint(0)
for rows.Next() {
var name string
- var low_cart, high_cart uint
- if result.err = rows.Scan(&name, &low_cart, &high_cart); result.err != nil {
+ var lowCart, highCart uint
+ if result.err = rows.Scan(&name, &lowCart, &highCart); result.err != nil {
return
}
- if high_cart >= low_cart {
- size := (high_cart - low_cart) + 1
- if size_min > size {
+ if highCart >= lowCart {
+ size := (highCart - lowCart) + 1
+ if sizeMin > size {
result.group = name
- size_min = size
+ sizeMin = size
}
}
}
@@ -207,12 +207,12 @@ func (self *RdDb) getLogTableName(log string) (logtable string, err error) {
return
}
-func (self *RdDb) getShowCarts(log string, low_cart, high_cart int) (carts []uint, err error) {
+func (self *RdDb) getShowCarts(log string, lowCart, highCart int) (carts []uint, err error) {
var logtable string
if logtable, err = self.getLogTableName(log); err != nil {
return
}
- q := fmt.Sprintf("select CART_NUMBER from %s where CART_NUMBER >= %d and CART_NUMBER <= %d order by COUNT;", logtable, low_cart, high_cart)
+ q := fmt.Sprintf("select CART_NUMBER from %s where CART_NUMBER >= %d and CART_NUMBER <= %d order by COUNT;", logtable, lowCart, highCart)
var rows *sql.Rows
if rows, err = self.dbh.Query(q); err != nil {
return
@@ -231,17 +231,17 @@ func (self *RdDb) getShowCarts(log string, low_cart, high_cart int) (carts []uin
func (self *RdDb) getShowInfo(showid uint) (result getShowInfoResult) {
var macros string
- var low_cart, high_cart int
- result.err = self.getShowInfoStmt.QueryRow(showid).Scan(&result.title, &macros, &result.group, &result.norm_lvl, &result.trim_lvl, &low_cart, &high_cart)
+ var lowCart, highCart int
+ result.err = self.getShowInfoStmt.QueryRow(showid).Scan(&result.title, &macros, &result.group, &result.normLvl, &result.trimLvl, &lowCart, &highCart)
if result.err != nil {
if result.err == sql.ErrNoRows {
result.err = fmt.Errorf("show '%d' not found", showid)
}
return
}
- result.norm_lvl /= 100
- result.trim_lvl /= 100
- result.carts, result.err = self.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], low_cart, high_cart)
+ result.normLvl /= 100
+ result.trimLvl /= 100
+ result.carts, result.err = self.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], lowCart, highCart)
return
}
@@ -259,7 +259,7 @@ func (self *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) {
}
func (self *RdDb) getMusicInfo(group string) (result getMusicInfoResult) {
- result.err = self.getMusicInfoStmt.QueryRow(group).Scan(&result.norm_lvl, &result.trim_lvl)
+ result.err = self.getMusicInfoStmt.QueryRow(group).Scan(&result.normLvl, &result.trimLvl)
if result.err != nil {
if result.err == sql.ErrNoRows {
result.err = fmt.Errorf("music pool '%s' not found", group)
@@ -301,14 +301,14 @@ type RdDbChan struct {
}
func (self *RdDbChan) GetPassword(username string, cached bool) (string, error) {
- res_ch := make(chan getPasswordResult)
+ resCh := make(chan getPasswordResult)
req := getPasswordRequest{}
req.username = username
req.cached = cached
- req.response = res_ch
+ req.response = resCh
self.getPasswordChan <- req
- res := <-res_ch
+ res := <-resCh
if res.err != nil {
return "", res.err
}
@@ -319,14 +319,14 @@ func (self *RdDbChan) CheckPassword(username, password string) (bool, error) {
cached := true
for {
- res_ch := make(chan getPasswordResult)
+ resCh := make(chan getPasswordResult)
req := getPasswordRequest{}
req.username = username
req.cached = cached
- req.response = res_ch
+ req.response = resCh
self.getPasswordChan <- req
- res := <-res_ch
+ res := <-resCh
if res.err != nil {
return false, res.err
}
@@ -343,13 +343,13 @@ func (self *RdDbChan) CheckPassword(username, password string) (bool, error) {
}
func (self *RdDbChan) GetGroupOfCart(cart uint) (string, error) {
- res_ch := make(chan getGroupOfCartResult)
+ resCh := make(chan getGroupOfCartResult)
req := getGroupOfCartRequest{}
req.cart = cart
- req.response = res_ch
+ req.response = resCh
self.getGroupOfCartChan <- req
- res := <-res_ch
+ res := <-resCh
if res.err != nil {
return "", res.err
}
@@ -357,27 +357,27 @@ func (self *RdDbChan) GetGroupOfCart(cart uint) (string, error) {
}
func (self *RdDbChan) GetShowInfo(showid uint) (string, int, int, []uint, error) {
- res_ch := make(chan getShowInfoResult)
+ resCh := make(chan getShowInfoResult)
req := getShowInfoRequest{}
req.showid = showid
- req.response = res_ch
+ req.response = resCh
self.getShowInfoChan <- req
- res := <-res_ch
+ res := <-resCh
if res.err != nil {
return "", 0, 0, nil, res.err
}
- return res.group, res.norm_lvl, res.trim_lvl, res.carts, nil
+ return res.group, res.normLvl, res.trimLvl, res.carts, nil
}
func (self *RdDbChan) CheckMusicGroup(groupname string) (bool, error) {
- res_ch := make(chan checkMusicGroupResult)
+ resCh := make(chan checkMusicGroupResult)
req := checkMusicGroupRequest{}
req.group = groupname
- req.response = res_ch
+ req.response = resCh
self.checkMusicGroupChan <- req
- res := <-res_ch
+ res := <-resCh
if res.err != nil {
return false, res.err
}
@@ -385,17 +385,17 @@ func (self *RdDbChan) CheckMusicGroup(groupname string) (bool, error) {
}
func (self *RdDbChan) GetMusicInfo(groupname string) (int, int, error) {
- res_ch := make(chan getMusicInfoResult)
+ resCh := make(chan getMusicInfoResult)
req := getMusicInfoRequest{}
req.group = groupname
- req.response = res_ch
+ req.response = resCh
self.getMusicInfoChan <- req
- res := <-res_ch
+ res := <-resCh
if res.err != nil {
return 0, 0, res.err
}
- return res.norm_lvl, res.trim_lvl, nil
+ return res.normLvl, res.trimLvl, nil
}
func (self *RdDb) GetInterface() *RdDbChan {
@@ -439,7 +439,7 @@ func NewRdDb(conf *Config) (db *RdDb, err error) {
db.quit = make(chan bool)
db.done = make(chan bool)
- db.password_cache = make(map[string]string)
+ db.passwordCache = make(map[string]string)
db.getPasswordChan = make(chan getPasswordRequest, 10)
db.getGroupOfCartChan = make(chan getGroupOfCartRequest, 10)
db.getShowInfoChan = make(chan getShowInfoRequest, 10)