summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport/importer.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimport/importer.go')
-rw-r--r--src/helsinki.at/rhimport/importer.go98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go
index abc99e8..e4f979f 100644
--- a/src/helsinki.at/rhimport/importer.go
+++ b/src/helsinki.at/rhimport/importer.go
@@ -50,8 +50,8 @@ func (self *ImportResult) fromRDWebResult(rdres *RDWebResult) {
}
}
-func add_cart(ctx *ImportContext, res *ImportResult) (err error) {
- rhdl.Printf("importer: add_cart() called for cart: %d", ctx.Cart)
+func addCart(ctx *ImportContext, res *ImportResult) (err error) {
+ rhdl.Printf("importer: addCart() called for cart: %d", ctx.Cart)
if ctx.GroupName == "" {
if err = ctx.getGroupOfCart(); err != nil {
@@ -85,7 +85,7 @@ func add_cart(ctx *ImportContext, res *ImportResult) (err error) {
w.Close()
var resp *http.Response
- if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
+ if resp, err = sendPostRequest(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
return
}
defer resp.Body.Close()
@@ -110,8 +110,8 @@ func add_cart(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func add_cut(ctx *ImportContext, res *ImportResult) (err error) {
- rhdl.Printf("importer: add_cut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
+func addCut(ctx *ImportContext, res *ImportResult) (err error) {
+ rhdl.Printf("importer: addCut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
var b bytes.Buffer
w := multipart.NewWriter(&b)
@@ -130,7 +130,7 @@ func add_cut(ctx *ImportContext, res *ImportResult) (err error) {
w.Close()
var resp *http.Response
- if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
+ if resp, err = sendPostRequest(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
return
}
defer resp.Body.Close()
@@ -157,8 +157,8 @@ func add_cut(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func remove_cart(ctx *ImportContext, res *ImportResult) (err error) {
- rhdl.Printf("importer: remove_cart() called for cart: %d", ctx.Cart)
+func removeCart(ctx *ImportContext, res *ImportResult) (err error) {
+ rhdl.Printf("importer: removeCart() called for cart: %d", ctx.Cart)
var b bytes.Buffer
w := multipart.NewWriter(&b)
@@ -177,7 +177,7 @@ func remove_cart(ctx *ImportContext, res *ImportResult) (err error) {
w.Close()
var resp *http.Response
- if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
+ if resp, err = sendPostRequest(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
return
}
defer resp.Body.Close()
@@ -191,8 +191,8 @@ func remove_cart(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func remove_cut(ctx *ImportContext, res *ImportResult) (err error) {
- rhdl.Printf("importer: remove_cut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
+func removeCut(ctx *ImportContext, res *ImportResult) (err error) {
+ rhdl.Printf("importer: removeCut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
var b bytes.Buffer
w := multipart.NewWriter(&b)
@@ -214,7 +214,7 @@ func remove_cut(ctx *ImportContext, res *ImportResult) (err error) {
w.Close()
var resp *http.Response
- if resp, err = send_post_request(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
+ if resp, err = sendPostRequest(ctx.conf.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
return
}
defer resp.Body.Close()
@@ -229,7 +229,7 @@ func remove_cut(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func send_post_request(url string, b *bytes.Buffer, contenttype string) (resp *http.Response, err error) {
+func sendPostRequest(url string, b *bytes.Buffer, contenttype string) (resp *http.Response, err error) {
var req *http.Request
if req, err = http.NewRequest("POST", url, b); err != nil {
return
@@ -245,7 +245,7 @@ func send_post_request(url string, b *bytes.Buffer, contenttype string) (resp *h
return
}
-func import_audio_create_request(ctx *ImportContext, easy *curl.CURL) (form *curl.Form, err error) {
+func importAudioCreateRequest(ctx *ImportContext, easy *curl.CURL) (form *curl.Form, err error) {
form = curl.NewForm()
if err = form.Add("COMMAND", "2"); err != nil {
@@ -282,8 +282,8 @@ func import_audio_create_request(ctx *ImportContext, easy *curl.CURL) (form *cur
return
}
-func import_audio(ctx *ImportContext, res *ImportResult) (err error) {
- rhdl.Printf("importer: import_audio() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
+func importAudio(ctx *ImportContext, res *ImportResult) (err error) {
+ rhdl.Printf("importer: importAudio() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
easy := curl.EasyInit()
if easy != nil {
@@ -293,7 +293,7 @@ func import_audio(ctx *ImportContext, res *ImportResult) (err error) {
easy.Setopt(curl.OPT_POST, true)
var form *curl.Form
- if form, err = import_audio_create_request(ctx, easy); err != nil {
+ if form, err = importAudioCreateRequest(ctx, easy); err != nil {
return
}
easy.Setopt(curl.OPT_HTTPPOST, form)
@@ -350,24 +350,24 @@ func import_audio(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func add_cart_cut(ctx *ImportContext, res *ImportResult) (err error) {
- if err = add_cart(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+func addCartCut(ctx *ImportContext, res *ImportResult) (err error) {
+ if err = addCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
- if err = add_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
- return remove_cart(ctx, &ImportResult{ResponseCode: http.StatusOK})
+ if err = addCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+ return removeCart(ctx, &ImportResult{ResponseCode: http.StatusOK})
}
return
}
-func remove_add_cart_cut(ctx *ImportContext, res *ImportResult) (err error) {
- if err = remove_cart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) {
+func removeAddCartCut(ctx *ImportContext, res *ImportResult) (err error) {
+ if err = removeCart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) {
return
}
- return add_cart_cut(ctx, res)
+ return addCartCut(ctx, res)
}
-func is_cart_member_of_show(ctx *ImportContext, res *ImportResult, carts []uint) (found bool) {
+func isCartMemberOfShow(ctx *ImportContext, res *ImportResult, carts []uint) (found bool) {
if ctx.Cart == 0 {
return true
}
@@ -382,33 +382,33 @@ func is_cart_member_of_show(ctx *ImportContext, res *ImportResult, carts []uint)
return false
}
-func clear_show_carts(ctx *ImportContext, res *ImportResult, carts []uint) (err error) {
+func clearShowCarts(ctx *ImportContext, res *ImportResult, carts []uint) (err error) {
if ctx.ClearShowCarts {
- orig_cart := ctx.Cart
+ origCart := ctx.Cart
for _, cart := range carts {
ctx.Cart = cart
- if err = remove_cart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) {
+ if err = removeCart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) {
return
}
}
- ctx.Cart = orig_cart
+ ctx.Cart = origCart
}
return
}
-func add_show_cart_cut(ctx *ImportContext, res *ImportResult, carts []uint) (err error) {
- if err = add_cart(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+func addShowCartCut(ctx *ImportContext, res *ImportResult, carts []uint) (err error) {
+ if err = addCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
for _, cart := range carts {
if cart == ctx.Cart {
- if err = add_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
- return remove_cart(ctx, &ImportResult{ResponseCode: http.StatusOK})
+ if err = addCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+ return removeCart(ctx, &ImportResult{ResponseCode: http.StatusOK})
}
return
}
}
- if err = remove_cart(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+ if err = removeCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
res.ResponseCode = http.StatusForbidden
@@ -416,7 +416,7 @@ func add_show_cart_cut(ctx *ImportContext, res *ImportResult, carts []uint) (err
return
}
-func cleanup_files(ctx *ImportContext) {
+func cleanupFiles(ctx *ImportContext) {
if ctx.DeleteSourceFile {
rhdl.Printf("importer: removing file: %s", ctx.SourceFile)
if err := os.Remove(ctx.SourceFile); err != nil {
@@ -435,7 +435,7 @@ func cleanup_files(ctx *ImportContext) {
}
func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
- defer cleanup_files(ctx)
+ defer cleanupFiles(ctx)
rhl.Printf("importer: ImportFile called with: show-id: %d, pool-name: '%s', cart/cut: %d/%d", ctx.ShowId, ctx.GroupName, ctx.Cart, ctx.Cut)
@@ -456,22 +456,22 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
rmCutOnErr := false
res = &ImportResult{ResponseCode: http.StatusOK}
if ctx.ShowId != 0 { // Import to a show
- var show_carts []uint
- if show_carts, err = ctx.getShowInfo(); err != nil {
+ var showCarts []uint
+ if showCarts, err = ctx.getShowInfo(); err != nil {
return
}
- if !is_cart_member_of_show(ctx, res, show_carts) {
+ if !isCartMemberOfShow(ctx, res, showCarts) {
return
}
- if err = clear_show_carts(ctx, res, show_carts); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) {
+ if err = clearShowCarts(ctx, res, showCarts); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) {
return
}
if ctx.ClearCart && !ctx.ClearShowCarts {
- if err = remove_add_cart_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+ if err = removeAddCartCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
} else {
- if err = add_show_cart_cut(ctx, res, show_carts); err != nil || res.ResponseCode != http.StatusOK {
+ if err = addShowCartCut(ctx, res, showCarts); err != nil || res.ResponseCode != http.StatusOK {
return
}
}
@@ -480,22 +480,22 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
if err = ctx.getMusicInfo(); err != nil {
return
}
- if err = add_cart_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+ if err = addCartCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
rmCartOnErr = true
} else if ctx.Cart != 0 && ctx.Cut == 0 { // Import to Cart
if ctx.ClearCart {
- if err = remove_add_cart_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+ if err = removeAddCartCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
rmCartOnErr = true
} else {
- if err = add_cut(ctx, res); err != nil {
+ if err = addCut(ctx, res); err != nil {
return
}
if res.ResponseCode != http.StatusOK {
- if err = add_cart_cut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+ if err = addCartCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
rmCartOnErr = true
@@ -506,7 +506,7 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
}
if ctx.Cart != 0 && ctx.Cut != 0 { // Import to specific Cut within Cart
- if err = import_audio(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
+ if err = importAudio(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
if err != nil {
rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", ctx.Cart, ctx.Cut, err)
} else {
@@ -515,11 +515,11 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
// Try to clean up after failed import
rmres := ImportResult{ResponseCode: http.StatusOK}
if rmCartOnErr {
- if rerr := remove_cart(ctx, &rmres); rerr != nil {
+ if rerr := removeCart(ctx, &rmres); rerr != nil {
return
}
} else if rmCutOnErr {
- if rerr := remove_cut(ctx, &rmres); rerr != nil {
+ if rerr := removeCut(ctx, &rmres); rerr != nil {
return
}
}