diff options
Diffstat (limited to 'src/helsinki.at/rhimport/importer.go')
-rw-r--r-- | src/helsinki.at/rhimport/importer.go | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index 1404259..f65515b 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/importer.go @@ -40,8 +40,8 @@ var ( ) type ImportContext struct { - *Config - *RdDb + conf *Config + rddb *RdDbChan UserName string Password string Trusted bool @@ -63,10 +63,10 @@ type ImportContext struct { ProgressCallBackData interface{} } -func NewImportContext(conf *Config, rddb *RdDb, user string) *ImportContext { +func NewImportContext(conf *Config, rddb *RdDbChan, user string) *ImportContext { ctx := new(ImportContext) - ctx.Config = conf - ctx.RdDb = rddb + ctx.conf = conf + ctx.rddb = rddb ctx.UserName = user ctx.Password = "" ctx.Trusted = false @@ -121,13 +121,14 @@ 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 = make(chan getPasswordResult) - ctx.RdDb.getPasswordChan <- req + req.response = res_ch + ctx.rddb.getPasswordChan <- req - res := <-req.response + res := <-res_ch if res.err != nil { return res.err } @@ -136,12 +137,13 @@ func (ctx *ImportContext) getPassword(cached bool) (err error) { } func (ctx *ImportContext) getGroupOfCart() error { + res_ch := make(chan getGroupOfCartResult) req := getGroupOfCartRequest{} req.cart = ctx.Cart - req.response = make(chan getGroupOfCartResult) - ctx.RdDb.getGroupOfCartChan <- req + req.response = res_ch + ctx.rddb.getGroupOfCartChan <- req - res := <-req.response + res := <-res_ch if res.err != nil { return res.err } @@ -150,12 +152,13 @@ func (ctx *ImportContext) getGroupOfCart() error { } func (ctx *ImportContext) getShowInfo() (carts []uint, err error) { + res_ch := make(chan getShowInfoResult) req := getShowInfoRequest{} req.showid = ctx.ShowId - req.response = make(chan getShowInfoResult) - ctx.RdDb.getShowInfoChan <- req + req.response = res_ch + ctx.rddb.getShowInfoChan <- req - res := <-req.response + res := <-res_ch if res.err != nil { err = res.err return @@ -170,12 +173,13 @@ func (ctx *ImportContext) getShowInfo() (carts []uint, err error) { } func (ctx *ImportContext) checkMusicGroup() (bool, error) { + res_ch := make(chan checkMusicGroupResult) req := checkMusicGroupRequest{} req.group = ctx.GroupName - req.response = make(chan checkMusicGroupResult) - ctx.RdDb.checkMusicGroupChan <- req + req.response = res_ch + ctx.rddb.checkMusicGroupChan <- req - res := <-req.response + res := <-res_ch if res.err != nil { return false, res.err } @@ -183,12 +187,13 @@ func (ctx *ImportContext) checkMusicGroup() (bool, error) { } func (ctx *ImportContext) getMusicInfo() (err error) { + res_ch := make(chan getMusicInfoResult) req := getMusicInfoRequest{} req.group = ctx.GroupName - req.response = make(chan getMusicInfoResult) - ctx.RdDb.getMusicInfoChan <- req + req.response = res_ch + ctx.rddb.getMusicInfoChan <- req - res := <-req.response + res := <-res_ch if res.err != nil { return res.err } @@ -251,7 +256,7 @@ func add_cart(ctx *ImportContext, res *ImportResult) (err error) { w.Close() var resp *http.Response - if resp, err = send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { + if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { return } defer resp.Body.Close() @@ -296,7 +301,7 @@ func add_cut(ctx *ImportContext, res *ImportResult) (err error) { w.Close() var resp *http.Response - if resp, err = send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { + if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { return } defer resp.Body.Close() @@ -343,7 +348,7 @@ func remove_cart(ctx *ImportContext, res *ImportResult) (err error) { w.Close() var resp *http.Response - if resp, err = send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { + if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { return } defer resp.Body.Close() @@ -380,7 +385,7 @@ func remove_cut(ctx *ImportContext, res *ImportResult) (err error) { w.Close() var resp *http.Response - if resp, err = send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { + if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil { return } defer resp.Body.Close() @@ -455,7 +460,7 @@ func import_audio(ctx *ImportContext, res *ImportResult) (err error) { if easy != nil { defer easy.Cleanup() - easy.Setopt(curl.OPT_URL, ctx.Config.RDXportEndpoint) + easy.Setopt(curl.OPT_URL, ctx.conf.RDXportEndpoint) easy.Setopt(curl.OPT_POST, true) var form *curl.Form |