diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-26 09:52:33 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-26 09:52:33 (GMT) |
commit | a03a9cf4b5b34a54d715a518b83919bb322c42c3 (patch) | |
tree | 34f4db05ce9fa2cf66d96e1e63dcbb0cf276c680 | |
parent | 62ebc38acc54335ed7c4b14551fae828efddc333 (diff) |
small refactoring
-rw-r--r-- | src/helsinki.at/rhimport/importer.go | 72 | ||||
-rw-r--r-- | src/helsinki.at/rhimport/rddb.go | 73 |
2 files changed, 80 insertions, 65 deletions
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index 7ce4033..28ca55a 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/importer.go @@ -142,84 +142,28 @@ func (ctx *ImportContext) SanityCheck() error { } func (ctx *ImportContext) getPassword(cached bool) (err error) { - res_ch := make(chan getPasswordResult) - req := getPasswordRequest{} - req.username = ctx.UserName - req.cached = cached - req.response = res_ch - ctx.rddb.getPasswordChan <- req - - res := <-res_ch - if res.err != nil { - return res.err - } - ctx.Password = res.password - return nil + ctx.Password, err = ctx.rddb.GetPassword(ctx.UserName, cached) + return } -func (ctx *ImportContext) getGroupOfCart() error { - res_ch := make(chan getGroupOfCartResult) - req := getGroupOfCartRequest{} - req.cart = ctx.Cart - req.response = res_ch - ctx.rddb.getGroupOfCartChan <- req - - res := <-res_ch - if res.err != nil { - return res.err - } - ctx.GroupName = res.group - return nil +func (ctx *ImportContext) getGroupOfCart() (err error) { + ctx.GroupName, err = ctx.rddb.GetGroupOfCart(ctx.Cart) + return } func (ctx *ImportContext) getShowInfo() (carts []uint, err error) { - res_ch := make(chan getShowInfoResult) - req := getShowInfoRequest{} - req.showid = ctx.ShowId - req.response = res_ch - ctx.rddb.getShowInfoChan <- req - - res := <-res_ch - if res.err != nil { - err = res.err - return - } - ctx.GroupName = res.group - ctx.NormalizationLevel = res.norm_lvl - ctx.AutotrimLevel = res.trim_lvl + ctx.GroupName, ctx.NormalizationLevel, ctx.AutotrimLevel, carts, err = ctx.rddb.GetShowInfo(ctx.ShowId) ctx.Channels = 2 ctx.UseMetaData = true - carts = res.carts return } func (ctx *ImportContext) checkMusicGroup() (bool, error) { - res_ch := make(chan checkMusicGroupResult) - req := checkMusicGroupRequest{} - req.group = ctx.GroupName - req.response = res_ch - ctx.rddb.checkMusicGroupChan <- req - - res := <-res_ch - if res.err != nil { - return false, res.err - } - return res.ismusic, nil + return ctx.rddb.CheckMusicGroup(ctx.GroupName) } func (ctx *ImportContext) getMusicInfo() (err error) { - res_ch := make(chan getMusicInfoResult) - req := getMusicInfoRequest{} - req.group = ctx.GroupName - req.response = res_ch - ctx.rddb.getMusicInfoChan <- req - - res := <-res_ch - if res.err != nil { - return res.err - } - ctx.NormalizationLevel = res.norm_lvl - ctx.AutotrimLevel = res.trim_lvl + ctx.NormalizationLevel, ctx.AutotrimLevel, err = ctx.rddb.GetMusicInfo(ctx.GroupName) ctx.Channels = 2 ctx.UseMetaData = true ctx.Cart = 0 diff --git a/src/helsinki.at/rhimport/rddb.go b/src/helsinki.at/rhimport/rddb.go index 7466d9c..ead1ac0 100644 --- a/src/helsinki.at/rhimport/rddb.go +++ b/src/helsinki.at/rhimport/rddb.go @@ -177,7 +177,22 @@ func (self *RdDb) getPassword(username string, cached bool) (result getPasswordR return } -func (self *RdDbChan) CheckPassword(username, password string) (result bool, err error) { +func (self *RdDbChan) GetPassword(username string, cached bool) (string, error) { + res_ch := make(chan getPasswordResult) + req := getPasswordRequest{} + req.username = username + req.cached = cached + req.response = res_ch + self.getPasswordChan <- req + + res := <-res_ch + if res.err != nil { + return "", res.err + } + return res.password, nil +} + +func (self *RdDbChan) CheckPassword(username, password string) (bool, error) { cached := true for { @@ -234,6 +249,20 @@ func (self *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) { return } +func (self *RdDbChan) GetGroupOfCart(cart uint) (string, error) { + res_ch := make(chan getGroupOfCartResult) + req := getGroupOfCartRequest{} + req.cart = cart + req.response = res_ch + self.getGroupOfCartChan <- req + + res := <-res_ch + if res.err != nil { + return "", res.err + } + return res.group, nil +} + func (self *RdDb) getLogTableName(log string) (logtable string, err error) { logtable = strings.Replace(log, " ", "_", -1) + "_LOG" if !mysqlTableNameRe.MatchString(logtable) { @@ -280,6 +309,20 @@ func (self *RdDb) getShowInfo(showid uint) (result getShowInfoResult) { return } +func (self *RdDbChan) GetShowInfo(showid uint) (string, int, int, []uint, error) { + res_ch := make(chan getShowInfoResult) + req := getShowInfoRequest{} + req.showid = showid + req.response = res_ch + self.getShowInfoChan <- req + + res := <-res_ch + if res.err != nil { + return "", 0, 0, nil, res.err + } + return res.group, res.norm_lvl, res.trim_lvl, res.carts, nil +} + func (self *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) { var cnt int if result.err = self.checkMusicGroupStmt.QueryRow(group).Scan(&cnt); result.err != nil { @@ -293,6 +336,20 @@ func (self *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) { return } +func (self *RdDbChan) CheckMusicGroup(groupname string) (bool, error) { + res_ch := make(chan checkMusicGroupResult) + req := checkMusicGroupRequest{} + req.group = groupname + req.response = res_ch + self.checkMusicGroupChan <- req + + res := <-res_ch + if res.err != nil { + return false, res.err + } + return res.ismusic, nil +} + func (self *RdDb) getMusicInfo(group string) (result getMusicInfoResult) { result.err = self.getMusicInfoStmt.QueryRow(group).Scan(&result.norm_lvl, &result.trim_lvl) if result.err != nil { @@ -304,6 +361,20 @@ func (self *RdDb) getMusicInfo(group string) (result getMusicInfoResult) { return } +func (self *RdDbChan) GetMusicInfo(groupname string) (int, int, error) { + res_ch := make(chan getMusicInfoResult) + req := getMusicInfoRequest{} + req.group = groupname + req.response = res_ch + self.getMusicInfoChan <- req + + res := <-res_ch + if res.err != nil { + return 0, 0, res.err + } + return res.norm_lvl, res.trim_lvl, nil +} + func (self *RdDb) dispatchRequests() { defer func() { self.done <- true }() for { |