diff --git a/.goreleaser.yml b/.goreleaser.yml index df029c8..5c49bc1 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -15,7 +15,6 @@ builds: - freebsd goarch: - amd64 - - "386" - arm - arm64 main: ./ diff --git a/.travis.yml b/.travis.yml index f59f71d..35f0995 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: -- "1.13.x" +- "1.15.x" env: global: diff --git a/api/aozoraapi/aozoraapi.go b/api/aozoraapi/aozoraapi.go index eb7fdd7..a478c31 100644 --- a/api/aozoraapi/aozoraapi.go +++ b/api/aozoraapi/aozoraapi.go @@ -34,36 +34,35 @@ func (a *AozoraAPI) Name() string { return a.svcType.String() } -///LookupRawData returns openBD raw data +//LookupRawData returns openBD raw data func (a *AozoraAPI) LookupRawData(id string) (io.Reader, error) { bookId, err := strconv.Atoi(id) if err != nil { - return nil, errs.Wrap( - err, + return nil, errs.New( fmt.Sprintf("invalid book id: %v", id), errs.WithContext("id", id), ) } b, err := a.server.CreateClient(aozora.WithContext(a.ctx), aozora.WithHttpClient(&http.Client{})).LookupBookRaw(bookId) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } return bytes.NewReader(b), nil } -///LookupBook returns Book data from openBD +//LookupBook returns Book data from openBD func (a *AozoraAPI) LookupBook(id string) (*entity.Book, error) { bookId, err := strconv.Atoi(id) if err != nil { - return nil, errs.Wrap( - err, + return nil, errs.New( fmt.Sprintf("invalid book id: %v", id), + errs.WithCause(err), errs.WithContext("id", id), ) } bk, err := a.server.CreateClient(aozora.WithContext(a.ctx), aozora.WithHttpClient(&http.Client{})).LookupBook(bookId) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } book := &entity.Book{ @@ -104,7 +103,7 @@ func getCreators(bk *aozora.Book) []entity.Creator { return creators } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/api/openbd/openbd.go b/api/openbd/openbd.go index fd90556..b427865 100644 --- a/api/openbd/openbd.go +++ b/api/openbd/openbd.go @@ -39,9 +39,9 @@ func (a *OpenBD) Name() string { func (a *OpenBD) LookupRawData(id string) (io.Reader, error) { res, err := a.server.CreateClient(obd.WithContext(a.ctx), obd.WithHttpClient(&http.Client{})).LookupBooksRaw([]string{id}) if err != nil { - return nil, errs.Wrap( - err, + return nil, errs.New( fmt.Sprintf("invalid book id: %v", id), + errs.WithCause(err), errs.WithContext("id", id), ) } @@ -52,14 +52,14 @@ func (a *OpenBD) LookupRawData(id string) (io.Reader, error) { func (a *OpenBD) LookupBook(id string) (*entity.Book, error) { data, err := a.LookupRawData(id) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } bd, err := unmarshalJSON(data) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } if !bd.IsValid() { - return nil, errs.Wrap(ecode.ErrInvalidAPIResponse, "", errs.WithContext("id", id)) + return nil, errs.Wrap(ecode.ErrInvalidAPIResponse, errs.WithContext("id", id)) } book := &entity.Book{ @@ -96,15 +96,15 @@ func getCreators(bd *obd.Book) []entity.Creator { func unmarshalJSON(jsondata io.Reader) (*obd.Book, error) { books := []obd.Book{} if err := json.NewDecoder(jsondata).Decode(&books); err != nil { - return nil, errs.Wrap(err, "") + return nil, errs.Wrap(err) } if len(books) == 0 { - return nil, errs.Wrap(ecode.ErrNoData, "") + return nil, errs.Wrap(ecode.ErrNoData) } return &books[0], nil } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/api/pa/entity.go b/api/pa/entity.go index d05b7fa..92ed1c1 100644 --- a/api/pa/entity.go +++ b/api/pa/entity.go @@ -213,13 +213,13 @@ func (r *Response) CheckError() error { func (r *Response) Output(typeName string) (*entity.Book, error) { if r == nil { - return nil, errs.Wrap(ecode.ErrNullPointer, "") + return nil, errs.Wrap(ecode.ErrNullPointer) } if err := r.CheckError(); err != nil { - return nil, errs.Wrap(err, "") + return nil, errs.Wrap(err) } if len(r.ItemsResult.Items) == 0 { - return nil, errs.Wrap(ecode.ErrNoData, "") + return nil, errs.Wrap(ecode.ErrNoData) } item := r.ItemsResult.Items[0] book := &entity.Book{ @@ -243,7 +243,7 @@ func (r *Response) Output(typeName string) (*entity.Book, error) { //JSON returns JSON data from Response instance func (r *Response) JSON() ([]byte, error) { b, err := json.Marshal(r) - return b, errs.Wrap(err, "") + return b, errs.Wrap(err) } //Stringer @@ -255,7 +255,7 @@ func (r *Response) String() string { return string(b) } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/api/pa/paapi5.go b/api/pa/paapi5.go index c1b41fc..93c96c6 100644 --- a/api/pa/paapi5.go +++ b/api/pa/paapi5.go @@ -54,7 +54,7 @@ func (a *PAAPI5) LookupRawData(id string) (io.Reader, error) { q := NewQuery(client.Marketplace(), client.PartnerTag(), client.PartnerType(), []string{id}) body, err := client.Request(q) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } return bytes.NewReader(body), nil @@ -64,17 +64,17 @@ func (a *PAAPI5) LookupRawData(id string) (io.Reader, error) { func (a *PAAPI5) LookupBook(id string) (*entity.Book, error) { r, err := a.LookupRawData(id) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } rsp := Response{} if err := json.NewDecoder(r).Decode(&rsp); err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } book, err := rsp.Output(a.Name()) - return book, errs.Wrap(err, "", errs.WithContext("id", id)) + return book, errs.Wrap(err, errs.WithContext("id", id)) } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/api/pa/query.go b/api/pa/query.go index 5a2b6b3..893d448 100644 --- a/api/pa/query.go +++ b/api/pa/query.go @@ -42,7 +42,7 @@ func (q *Query) Operation() paapi5.Operation { func (q *Query) Payload() ([]byte, error) { if q == nil { - return nil, errs.Wrap(paapi5.ErrNullPointer, "") + return nil, errs.Wrap(paapi5.ErrNullPointer) } q.Resources = []string{ "Images.Primary.Medium", @@ -54,7 +54,7 @@ func (q *Query) Payload() ([]byte, error) { "ItemInfo.Title", } b, err := json.Marshal(q) - return b, errs.Wrap(err, "") + return b, errs.Wrap(err) } func (q *Query) String() string { @@ -65,7 +65,7 @@ func (q *Query) String() string { return string(b) } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/ecode/ecode_test.go b/ecode/ecode_test.go index ebcc7b9..04187a8 100644 --- a/ecode/ecode_test.go +++ b/ecode/ecode_test.go @@ -1,11 +1,8 @@ package ecode import ( - "errors" "fmt" "testing" - - "github.com/spiegel-im-spiegel/errs" ) func TestECodeError(t *testing.T) { @@ -32,95 +29,7 @@ func TestECodeError(t *testing.T) { } } -func TestECodeErrorEquality(t *testing.T) { - testCases := []struct { - err1 error - err2 error - res bool - }{ - {err1: ErrNullPointer, err2: ErrNullPointer, res: true}, - {err1: ErrNullPointer, err2: errs.Wrap(ErrNullPointer, "wrapping error"), res: false}, - {err1: ErrNullPointer, err2: nil, res: false}, - {err1: ErrNullPointer, err2: ECode(0), res: false}, - } - - for _, tc := range testCases { - res := errors.Is(tc.err1, tc.err2) - if res != tc.res { - t.Errorf("\"%v\" == \"%v\" ? %v, want %v", tc.err1, tc.err2, res, tc.res) - } - } -} - -func TestWrapError(t *testing.T) { - testCases := []struct { - err error - msg string - str string - }{ - {err: ErrNullPointer, msg: "wrapping error", str: "wrapping error: Null reference instance"}, - } - - for _, tc := range testCases { - we := errs.Wrap(tc.err, tc.msg) - if we.Error() != tc.str { - t.Errorf("wrapError.Error() == \"%v\", want \"%v\"", we.Error(), tc.str) - } - fmt.Printf("Info(TestWrapError): %+v\n", we) - } -} - -func TestWrapNilError(t *testing.T) { - if we := errs.Wrap(nil, "null error"); we != nil { - t.Errorf("Wrap(nil) == \"%v\", want nil.", we) - } -} - -func TestWrapfError(t *testing.T) { - testCases := []struct { - err error - msg string - str string - }{ - {err: ErrNullPointer, msg: "wrapping error", str: "wrapping error: Null reference instance"}, - } - - for _, tc := range testCases { - we := errs.Wrap(tc.err, tc.msg) - if we.Error() != tc.str { - t.Errorf("wrapError.Error() == \"%v\", want \"%v\"", we.Error(), tc.str) - } - fmt.Printf("Info(TestWrapfError): %+v\n", we) - } -} - -func TestWrapfNilError(t *testing.T) { - if we := errs.Wrap(nil, "null error"); we != nil { - t.Errorf("Wrapf(nil) == \"%v\", want nil.", we) - } -} - -func TestWrapErrorEquality(t *testing.T) { - testCases := []struct { - err1 error - err2 error - res bool - }{ - {err1: errs.Wrap(ErrNullPointer, "wrapping error"), err2: ErrNullPointer, res: true}, - {err1: errs.Wrap(ErrNullPointer, "wrapping error"), err2: nil, res: false}, - {err1: errs.Wrap(ErrNullPointer, "wrapping error"), err2: ECode(0), res: false}, - {err1: errs.Wrap(ErrNullPointer, "wrapping error"), err2: errs.Wrap(ECode(0), "wrapping error"), res: false}, - } - - for _, tc := range testCases { - res := errors.Is(tc.err1, tc.err2) - if res != tc.res { - t.Errorf("\"%v\" == \"%v\" ? %v, want %v", tc.err1, tc.err2, res, tc.res) - } - } -} - -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/entity/book.go b/entity/book.go index 82f36d0..add9647 100644 --- a/entity/book.go +++ b/entity/book.go @@ -76,23 +76,23 @@ func ImportBookFromJSON(r io.Reader) (*Book, error) { dec := json.NewDecoder(r) bk := Book{} err := dec.Decode(&bk) - return &bk, errs.Wrap(err, "") + return &bk, errs.Wrap(err) } func (b *Book) Format(tmpltPath string) ([]byte, error) { if b == nil { - return nil, errs.Wrap(ecode.ErrNullPointer, "", errs.WithContext("tmpltPath", tmpltPath)) + return nil, errs.Wrap(ecode.ErrNullPointer, errs.WithContext("tmpltPath", tmpltPath)) } if len(tmpltPath) == 0 { b, err := json.Marshal(b) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("tmpltPath", tmpltPath)) + return nil, errs.Wrap(err, errs.WithContext("tmpltPath", tmpltPath)) } return b, nil } buf, err := format.ByTemplateFile(b, tmpltPath) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("tmpltPath", tmpltPath)) + return nil, errs.Wrap(err, errs.WithContext("tmpltPath", tmpltPath)) } return buf.Bytes(), nil } @@ -117,7 +117,7 @@ func (b *Book) CopyFrom(src *Book) *Book { return b } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/entity/values/date.go b/entity/values/date.go index 435f42b..6aeaf55 100644 --- a/entity/values/date.go +++ b/entity/values/date.go @@ -46,7 +46,7 @@ func (t *Date) UnmarshalJSON(b []byte) error { var lastErr error for _, tmplt := range timeTemplate1 { if tm, err := time.Parse(tmplt, s); err != nil { - lastErr = errs.Wrap(err, "", errs.WithContext("time_string", s), errs.WithContext("time_template", tmplt)) + lastErr = errs.Wrap(err, errs.WithContext("time_string", s), errs.WithContext("time_template", tmplt)) } else { *t = Date{tm} return nil @@ -57,7 +57,7 @@ func (t *Date) UnmarshalJSON(b []byte) error { var lastErr error for _, tmplt := range timeTemplate2 { if tm, err := time.Parse(tmplt, s); err != nil { - lastErr = errs.Wrap(err, "", errs.WithContext("time_string", s), errs.WithContext("time_template", tmplt)) + lastErr = errs.Wrap(err, errs.WithContext("time_string", s), errs.WithContext("time_template", tmplt)) } else { *t = Date{tm} return nil diff --git a/facade/facade.go b/facade/facade.go index a0a1fd0..c8cf83d 100644 --- a/facade/facade.go +++ b/facade/facade.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/spiegel-im-spiegel/books-data/ecode" + "github.com/spiegel-im-spiegel/errs" "github.com/spiegel-im-spiegel/gocli/config" "github.com/spiegel-im-spiegel/gocli/exitcode" "github.com/spiegel-im-spiegel/gocli/rwi" @@ -36,7 +37,7 @@ func newRootCmd(ui *rwi.RWI, args []string) *cobra.Command { Short: "Search for books data", Long: "Search for books data", RunE: func(cmd *cobra.Command, args []string) error { - return debugPrint(ui, ecode.ErrNoCommand) + return debugPrint(ui, errs.Wrap(ecode.ErrNoCommand)) }, } rootCmd.SetArgs(args) //arguments of command-line @@ -125,7 +126,7 @@ func Execute(ui *rwi.RWI, args []string) (exit exitcode.ExitCode) { return } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/facade/history.go b/facade/history.go index f5da208..50d1324 100644 --- a/facade/history.go +++ b/facade/history.go @@ -20,14 +20,14 @@ func newHistroyCmd(ui *rwi.RWI) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { logf := viper.GetString("review-log") if len(logf) == 0 { - return debugPrint(ui, errs.Wrap(ecode.ErrNoData, "error in history command")) + return debugPrint(ui, errs.New("error in history command", errs.WithCause(ecode.ErrNoData))) } revs, err := logger.ImportJSONFile(logf) if err != nil { return debugPrint(ui, err) } if len(revs) == 0 { - return debugPrint(ui, errs.Wrap(ecode.ErrNoData, "error in history command")) + return debugPrint(ui, errs.New("error in history command", errs.WithCause(ecode.ErrNoData))) } var rev *review.Review = nil @@ -44,7 +44,7 @@ func newHistroyCmd(ui *rwi.RWI) *cobra.Command { rev = revs.Find(api.TypeAozoraAPI.String(), card) } if rev == nil { - return debugPrint(ui, errs.Wrap(ecode.ErrNoData, "error in history command")) + return debugPrint(ui, errs.New("error in history command", errs.WithCause(ecode.ErrNoData))) } b, err := rev.Format(tmpltPath) @@ -59,7 +59,7 @@ func newHistroyCmd(ui *rwi.RWI) *cobra.Command { return historyCmd } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/facade/paapi.go b/facade/paapi.go index 0fd90cf..5a245e5 100644 --- a/facade/paapi.go +++ b/facade/paapi.go @@ -24,19 +24,19 @@ type paapiParams struct { func getPaapiParams() (*paapiParams, error) { marketplace := viper.GetString("marketplace") if len(marketplace) == 0 { - return nil, errs.Wrap(ecode.ErrInvalidAPIParameter, "marketplace is empty") + return nil, errs.New("marketplace is empty", errs.WithCause(ecode.ErrInvalidAPIParameter)) } associateTag := viper.GetString("associate-tag") if len(associateTag) == 0 { - return nil, errs.Wrap(ecode.ErrInvalidAPIParameter, "associate-tag is empty") + return nil, errs.New("associate-tag is empty", errs.WithCause(ecode.ErrInvalidAPIParameter)) } accessKey := viper.GetString("access-key") if len(accessKey) == 0 { - return nil, errs.Wrap(ecode.ErrInvalidAPIParameter, "access-key is empty") + return nil, errs.New("access-key is empty", errs.WithCause(ecode.ErrInvalidAPIParameter)) } secretKey := viper.GetString("secret-key") if len(secretKey) == 0 { - return nil, errs.Wrap(ecode.ErrInvalidAPIParameter, "secret-key is empty") + return nil, errs.New("secret-key is empty", errs.WithCause(ecode.ErrInvalidAPIParameter)) } return &paapiParams{marketplace: marketplace, associateTag: associateTag, accessKey: accessKey, secretKey: secretKey}, nil } @@ -57,11 +57,11 @@ func searchPAAPI(ctx context.Context, id string, p *paapiParams, rawFlag bool) ( } book, err := createPAAPI(ctx, p).LookupBook(id) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } b, err := book.Format(tmpltPath) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("id", id)) + return nil, errs.Wrap(err, errs.WithContext("id", id)) } return bytes.NewReader(b), nil } @@ -70,7 +70,7 @@ func findPAAPI(ctx context.Context, id string, p *paapiParams) (*entity.Book, er return createPAAPI(ctx, p).LookupBook(id) } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/facade/review.go b/facade/review.go index cd77311..9184d53 100644 --- a/facade/review.go +++ b/facade/review.go @@ -27,38 +27,38 @@ func newReviewCmd(ui *rwi.RWI) *cobra.Command { //pipe flag pipeFlag, err := cmd.Flags().GetBool("pipe") if err != nil { - return errs.Wrap(err, "--pipe") + return errs.New("--pipe", errs.WithCause(err)) } //Ratins rating, err := cmd.Flags().GetInt("rating") if err != nil { - return errs.Wrap(err, "--rating") + return errs.New("--rating", errs.WithCause(err)) } //Date of review dt, err := cmd.Flags().GetString("review-date") if err != nil { - return errs.Wrap(err, "--review-date") + return errs.New("--review-date", errs.WithCause(err)) } //URL of book page bookpage, err := cmd.Flags().GetString("bookpage-url") if err != nil { - return errs.Wrap(err, "--bookpage-url") + return errs.New("--bookpage-url", errs.WithCause(err)) } //URL of book cover image bookcover, err := cmd.Flags().GetString("image-url") if err != nil { - return errs.Wrap(err, "--image-url") + return errs.New("--image-url", errs.WithCause(err)) } //Description desc := "" if pipeFlag { w := &strings.Builder{} if _, err := io.Copy(w, ui.Reader()); err != nil { - return debugPrint(ui, errs.Wrap(err, "Cannot read Stdin")) + return debugPrint(ui, errs.New("Cannot read Stdin", errs.WithCause(err))) } desc = w.String() } else if len(args) > 1 { - return errs.Wrap(os.ErrInvalid, strings.Join(args, " ")) + return errs.Wrap(os.ErrInvalid, errs.WithContext("args", strings.Join(args, ","))) } else if len(args) == 1 { desc = args[0] } @@ -100,7 +100,7 @@ func newReviewCmd(ui *rwi.RWI) *cobra.Command { } } if err == nil && bk == nil { - err = errs.Wrap(ecode.ErrNoData, "error in review command") + err = errs.New("error in review command", errs.WithCause(ecode.ErrNoData)) } if err != nil { return debugPrint(ui, err) @@ -141,16 +141,16 @@ func updateReviewLog(rev *review.Review) error { } revs, err := logger.ImportJSONFile(path) if err != nil { - return errs.Wrap(err, "") + return errs.Wrap(err) } revs = revs.Append(rev) if err := revs.ExportJSONFile(path); err != nil { - return errs.Wrap(err, "") + return errs.Wrap(err) } return nil } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/facade/search.go b/facade/search.go index 73a9694..b0fb607 100644 --- a/facade/search.go +++ b/facade/search.go @@ -2,7 +2,6 @@ package facade import ( "context" - "errors" "os" "github.com/spf13/cobra" @@ -22,7 +21,7 @@ func newSearchCmd(ui *rwi.RWI) *cobra.Command { //Raw flag (PA-API) rawFlag, err := cmd.Flags().GetBool("raw") if err != nil { - return errs.Wrap(err, "--raw") + return errs.New("--raw", errs.WithCause(err)) } //Create context @@ -78,14 +77,14 @@ func newSearchCmd(ui *rwi.RWI) *cobra.Command { func checkError(err error) bool { switch true { - case errors.Is(err, ecode.ErrInvalidAPIParameter), errors.Is(err, ecode.ErrInvalidAPIResponse), errors.Is(err, ecode.ErrNoData): + case errs.Is(err, ecode.ErrInvalidAPIParameter), errs.Is(err, ecode.ErrInvalidAPIResponse), errs.Is(err, ecode.ErrNoData): return true default: return false } } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/format/format.go b/format/format.go index 27ec70c..1c070c3 100644 --- a/format/format.go +++ b/format/format.go @@ -13,13 +13,13 @@ import ( func ByTemplateFile(obj interface{}, tmpltPath string) (*bytes.Buffer, error) { file, err := os.Open(tmpltPath) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("tmpltPath", tmpltPath)) + return nil, errs.Wrap(err, errs.WithContext("tmpltPath", tmpltPath)) } defer file.Close() tmplt := &strings.Builder{} if _, err := io.Copy(tmplt, file); err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("tmpltPath", tmpltPath)) + return nil, errs.Wrap(err, errs.WithContext("tmpltPath", tmpltPath)) } return Do(obj, tmplt.String()) } @@ -28,16 +28,16 @@ func ByTemplateFile(obj interface{}, tmpltPath string) (*bytes.Buffer, error) { func Do(obj interface{}, tmplt string) (*bytes.Buffer, error) { t, err := template.New("Formatting").Parse(tmplt) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("tmplt", tmplt)) + return nil, errs.Wrap(err, errs.WithContext("tmplt", tmplt)) } buf := &bytes.Buffer{} if err := t.Execute(buf, obj); err != nil { - return buf, errs.Wrap(err, "", errs.WithContext("tmplt", tmplt)) + return buf, errs.Wrap(err, errs.WithContext("tmplt", tmplt)) } return buf, nil } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/go.mod b/go.mod index 44fd636..3d1133f 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/spiegel-im-spiegel/books-data -go 1.13 +go 1.15 require ( - github.com/spf13/cobra v0.0.5 + github.com/spf13/cobra v1.0.0 github.com/spf13/viper v1.4.0 - github.com/spiegel-im-spiegel/aozora-api v0.2.3 - github.com/spiegel-im-spiegel/errs v0.3.2 + github.com/spiegel-im-spiegel/aozora-api v0.2.5 + github.com/spiegel-im-spiegel/errs v1.0.0 github.com/spiegel-im-spiegel/gocli v0.10.1 - github.com/spiegel-im-spiegel/openbd-api v0.2.3 - github.com/spiegel-im-spiegel/pa-api v0.5.0 + github.com/spiegel-im-spiegel/openbd-api v0.2.5 + github.com/spiegel-im-spiegel/pa-api v0.7.1 ) diff --git a/go.sum b/go.sum index 75a426d..b1ebf2f 100644 --- a/go.sum +++ b/go.sum @@ -10,11 +10,10 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= @@ -72,7 +71,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -80,30 +80,28 @@ github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= -github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= +github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= -github.com/spiegel-im-spiegel/aozora-api v0.2.3 h1:p8eLcYDH7si44BKqypaJ0F/LPuyEN/lJrWIkr1r3NVY= -github.com/spiegel-im-spiegel/aozora-api v0.2.3/go.mod h1:U2yllfLDS27UTOUM08UTg6d0X7Wv980d9fOmt+aLtY0= -github.com/spiegel-im-spiegel/errs v0.3.2 h1:D4jUouZHBto4Vg+kxc0QNChf3aMynM3FDMNPAq64i2U= -github.com/spiegel-im-spiegel/errs v0.3.2/go.mod h1:NwHSe6m3oAhRj2bAkkbzz9xAffIDNcP9uTdyJd9fJNs= +github.com/spiegel-im-spiegel/aozora-api v0.2.5 h1:0gLr4EkDt6iqYtNZb2zhkIDStwp6Y92ClMu65QvMF5U= +github.com/spiegel-im-spiegel/aozora-api v0.2.5/go.mod h1:5Iz1C/Bu+8CvEXVOktUILPzaJN1p8rUP5oYsVWhxe3g= +github.com/spiegel-im-spiegel/errs v1.0.0 h1:tT/MJRUCFZWDTCTXnRFbrxzcJVsjdardQvG5LybgO/0= +github.com/spiegel-im-spiegel/errs v1.0.0/go.mod h1:UoasJYYujMcdkbT9USv8dfZWoMyaY3btqQxoLJImw0A= github.com/spiegel-im-spiegel/gocli v0.10.1 h1:XWyq4dKFp2xTjiH2P2bxPZyi0++4IHp9HOksgGdfwpA= github.com/spiegel-im-spiegel/gocli v0.10.1/go.mod h1:9vRvly2giutJ2sAtQjrw570p9ulJA3twgKlurmnj12g= -github.com/spiegel-im-spiegel/openbd-api v0.2.3 h1:3iV0TEQmznT8jxoYFlVM1ZUd1vhi3owUhvbrevB/FvM= -github.com/spiegel-im-spiegel/openbd-api v0.2.3/go.mod h1:M258g8imPwlFkoJR+wlfVVsMZJIKJlKx46Fzf4d2dr8= -github.com/spiegel-im-spiegel/pa-api v0.5.0 h1:erwGRBgoSy24NdVE+DPi7P3mViGz9Tz4TKkPkP+f3Ak= -github.com/spiegel-im-spiegel/pa-api v0.5.0/go.mod h1:2ugBqfnaqLnBtKd/rDmOqOhFum5thuXwojf8Uh98h+k= +github.com/spiegel-im-spiegel/openbd-api v0.2.5 h1:C18WJocYg1n2jZYFinQTwJNIzYZInGRVlXStxY1sIbI= +github.com/spiegel-im-spiegel/openbd-api v0.2.5/go.mod h1:HLjjBAo9/nJcNtzP5Z3+2Th6gf/BRX7jnnKAX94pOuw= +github.com/spiegel-im-spiegel/pa-api v0.7.1 h1:7sbMgo3dapAPqxRtG1bIjkpsDmwSJYybKmd1fNWd9co= +github.com/spiegel-im-spiegel/pa-api v0.7.1/go.mod h1:gEFPr+w0VwtNJFzWnR/VeVvuVna/9tmoch0LYTO0C+0= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -111,7 +109,6 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -128,7 +125,6 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= diff --git a/review/logger/reviews.go b/review/logger/reviews.go index b15147c..272d0ac 100644 --- a/review/logger/reviews.go +++ b/review/logger/reviews.go @@ -22,7 +22,7 @@ func ImportJSONFile(path string) (Reviews, error) { defer file.Close() rv, err := ImportJSON(file) - return rv, errs.Wrap(err, "", errs.WithContext("path", path)) + return rv, errs.Wrap(err, errs.WithContext("path", path)) } //ImportJSONFile import Reviews data with JSON format @@ -30,7 +30,7 @@ func ImportJSON(r io.Reader) (Reviews, error) { dec := json.NewDecoder(r) revs := Reviews{} err := dec.Decode(&revs) - return revs, errs.Wrap(err, "") + return revs, errs.Wrap(err) } //exportJSON returns byte string with JSON format @@ -39,14 +39,14 @@ func (revs Reviews) exportJSON() (*bytes.Buffer, error) { enc := json.NewEncoder(buf) enc.SetIndent("", " ") err := enc.Encode(revs) - return buf, errs.Wrap(err, "") + return buf, errs.Wrap(err) } //ExportJSONFile outputs file with JSON format func (revs Reviews) ExportJSONFile(path string) error { file, err := os.Create(path) if err != nil { - return errs.Wrap(err, "", errs.WithContext("path", path)) + return errs.Wrap(err, errs.WithContext("path", path)) } defer file.Close() @@ -55,7 +55,7 @@ func (revs Reviews) ExportJSONFile(path string) error { return err } _, err = io.Copy(file, b) - return errs.Wrap(err, "", errs.WithContext("path", path)) + return errs.Wrap(err, errs.WithContext("path", path)) } func (revs Reviews) String() string { @@ -87,7 +87,7 @@ func (revs Reviews) Append(rev *review.Review) Reviews { return revs } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/review/review.go b/review/review.go index bfe0ba0..746fdab 100644 --- a/review/review.go +++ b/review/review.go @@ -101,18 +101,18 @@ func (rev *Review) SetRating(r int) *Review { func (r *Review) Format(tmpltPath string) ([]byte, error) { if r == nil { - return nil, errs.Wrap(ecode.ErrNullPointer, "", errs.WithContext("tmpltPath", tmpltPath)) + return nil, errs.Wrap(ecode.ErrNullPointer, errs.WithContext("tmpltPath", tmpltPath)) } if len(tmpltPath) == 0 { b, err := json.Marshal(r) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("tmpltPath", tmpltPath)) + return nil, errs.Wrap(err, errs.WithContext("tmpltPath", tmpltPath)) } return b, nil } buf, err := format.ByTemplateFile(r, tmpltPath) if err != nil { - return nil, errs.Wrap(err, "", errs.WithContext("tmpltPath", tmpltPath)) + return nil, errs.Wrap(err, errs.WithContext("tmpltPath", tmpltPath)) } return buf.Bytes(), nil } @@ -139,7 +139,7 @@ func (r *Review) CopyFrom(src *Review) *Review { return r } -/* Copyright 2019 Spiegel +/* Copyright 2019,2020 Spiegel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.