From f390aaa79bef626f69ced73b3eeb1f1ffea93c6d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 5 Jan 2016 15:33:38 +0100 Subject: replaces FetchResult by ImportResult diff --git a/src/helsinki.at/rhimport/core.go b/src/helsinki.at/rhimport/core.go index f74f422..bb92d30 100644 --- a/src/helsinki.at/rhimport/core.go +++ b/src/helsinki.at/rhimport/core.go @@ -54,6 +54,13 @@ func init() { type ImportProgressCB func(step int, stepName string, progress float64, userdata interface{}) bool type ImportDoneCB func(ImportResult, interface{}) bool +type ImportResult struct { + ResponseCode int + ErrorString string + Cart uint + Cut uint +} + type ImportContext struct { conf *Config rddb *RdDbChan diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go index 55b814c..f5d5420 100644 --- a/src/helsinki.at/rhimport/fetcher.go +++ b/src/helsinki.at/rhimport/fetcher.go @@ -39,11 +39,6 @@ import ( "time" ) -type FetchResult struct { - ResponseCode int - ErrorString string -} - type FetcherCurlCBData struct { basepath string filename string @@ -91,7 +86,7 @@ func curlWriteCallback(ptr []byte, userdata interface{}) bool { return true } -func fetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) { +func fetchFileCurl(ctx *ImportContext, res *ImportResult, uri *url.URL) (err error) { rhl.Printf("curl-based fetcher called for '%s'", ctx.SourceUri) easy := curl.EasyInit() @@ -155,7 +150,7 @@ func fetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err erro return } -func fetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) { +func fetchFileLocal(ctx *ImportContext, res *ImportResult, uri *url.URL) (err error) { rhl.Printf("Local fetcher called for '%s'", ctx.SourceUri) if ctx.ProgressCallBack != nil { if keep := ctx.ProgressCallBack(1, "fetching", 0.0, ctx.ProgressCallBackData); !keep { @@ -192,7 +187,7 @@ func fetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err err return } -func fetchFileFake(ctx *ImportContext, res *FetchResult, uri *url.URL) error { +func fetchFileFake(ctx *ImportContext, res *ImportResult, uri *url.URL) error { rhdl.Printf("Fake fetcher for '%s'", ctx.SourceUri) if duration, err := strconv.ParseUint(uri.Host, 10, 32); err != nil { @@ -226,7 +221,7 @@ func fetchFileFake(ctx *ImportContext, res *FetchResult, uri *url.URL) error { return nil } -type FetchFunc func(*ImportContext, *FetchResult, *url.URL) (err error) +type FetchFunc func(*ImportContext, *ImportResult, *url.URL) (err error) // TODO: implement fetchers for: // archiv:// @@ -262,7 +257,7 @@ func fetcherInit() { } } -func checkPassword(ctx *ImportContext, result *FetchResult) (err error) { +func checkPassword(ctx *ImportContext, result *ImportResult) (err error) { ok := false if ok, err = ctx.rddb.CheckPassword(ctx.UserName, ctx.Password); err != nil { return @@ -274,8 +269,8 @@ func checkPassword(ctx *ImportContext, result *FetchResult) (err error) { return } -func FetchFile(ctx *ImportContext) (res *FetchResult, err error) { - res = &FetchResult{ResponseCode: http.StatusOK} +func FetchFile(ctx *ImportContext) (res *ImportResult, err error) { + res = &ImportResult{ResponseCode: http.StatusOK} var uri *url.URL if uri, err = url.Parse(ctx.SourceUri); err != nil { diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index e4f979f..4a0bece 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/importer.go @@ -35,13 +35,6 @@ import ( "path" ) -type ImportResult struct { - ResponseCode int - ErrorString string - Cart uint - Cut uint -} - func (self *ImportResult) fromRDWebResult(rdres *RDWebResult) { self.ResponseCode = rdres.ResponseCode self.ErrorString = rdres.ErrorString diff --git a/src/helsinki.at/rhimport/session.go b/src/helsinki.at/rhimport/session.go index 80acee1..e0f1a4b 100644 --- a/src/helsinki.at/rhimport/session.go +++ b/src/helsinki.at/rhimport/session.go @@ -108,7 +108,7 @@ func sessionImportRun(ctx ImportContext, done chan<- ImportResult) { done <- ImportResult{http.StatusInternalServerError, err.Error(), 0, 0} return } else if res.ResponseCode != http.StatusOK { - done <- ImportResult{res.ResponseCode, res.ErrorString, 0, 0} + done <- *res return } diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go index 7a7af92..8af421f 100644 --- a/src/helsinki.at/rhimportd/ctrlWebSimple.go +++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go @@ -135,27 +135,26 @@ func webSimpleHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions * return } - var fres *rhimport.FetchResult - if fres, err = rhimport.FetchFile(ctx); err != nil { + var res *rhimport.ImportResult + if res, err = rhimport.FetchFile(ctx); err != nil { webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error()) return } - if fres.ResponseCode != http.StatusOK { - webSimpleErrorResponse(w, fres.ResponseCode, fres.ErrorString) + if res.ResponseCode != http.StatusOK { + webSimpleErrorResponse(w, res.ResponseCode, res.ErrorString) return } - var ires *rhimport.ImportResult - if ires, err = rhimport.ImportFile(ctx); err != nil { + if res, err = rhimport.ImportFile(ctx); err != nil { webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error()) return } - if ires.ResponseCode == http.StatusOK { + if res.ResponseCode == http.StatusOK { rhl.Println("ImportFile succesfully imported", ctx.SourceFile) } else { rhl.Println("ImportFile import of", ctx.SourceFile, "was unsuccesful") } - webSimpleResponse(w, ires) + webSimpleResponse(w, res) return } -- cgit v0.10.2