diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-01-05 14:33:38 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-01-05 14:33:38 (GMT) |
commit | f390aaa79bef626f69ced73b3eeb1f1ffea93c6d (patch) | |
tree | f8ec04c2a7a7e7485c7541f2a3c108adbdcee084 | |
parent | f2e1ae7dc36e6894d5f8e1d5b512d6b5437d4f21 (diff) |
replaces FetchResult by ImportResult
-rw-r--r-- | src/helsinki.at/rhimport/core.go | 7 | ||||
-rw-r--r-- | src/helsinki.at/rhimport/fetcher.go | 19 | ||||
-rw-r--r-- | src/helsinki.at/rhimport/importer.go | 7 | ||||
-rw-r--r-- | src/helsinki.at/rhimport/session.go | 2 | ||||
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlWebSimple.go | 15 |
5 files changed, 22 insertions, 28 deletions
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 } |