diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f4a35c..22a68b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.15 + go-version: 1.16 - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bb79263..d55ca33 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,25 +1,24 @@ name: lint on: push: - tags: - - v* branches: - master pull_request: jobs: golangci: - strategy: - matrix: - go-version: [1.15.x] - os: [ubuntu-latest] name: lint - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: ^1.16 - name: golangci-lint uses: golangci/golangci-lint-action@v2 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. version: latest + # Optional: golangci-lint command line arguments. + args: --enable gosec - name: testing run: go test ./... diff --git a/.github/workflows/vulns.yml b/.github/workflows/vulns.yml index 3df4099..7f5b264 100644 --- a/.github/workflows/vulns.yml +++ b/.github/workflows/vulns.yml @@ -14,8 +14,10 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.16 + - name: install depm + run: go install github.com/spiegel-im-spiegel/depm@latest - name: WriteGoList - run: go list -json -m all > go.list + run: depm list --json > go.list - name: Nancy uses: sonatype-nexus-community/nancy-github-action@main diff --git a/.gitignore b/.gitignore index 6f23615..6ed1e94 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # Other files and folders *.bak dist/ +.task/ diff --git a/.goreleaser.yml b/.goreleaser.yml index 5c49bc1..08df0ca 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -20,7 +20,7 @@ builds: main: ./ flags: - -trimpath - ldflags: -s -w -X github.com/spiegel-im-spiegel/books-data/facade.Version={{ .Version }} + ldflags: -s -w -X github.com/spiegel-im-spiegel/books-data/facade.Version=v{{ .Version }} binary: books-data archives: @@ -43,6 +43,7 @@ archives: - LICENSE* - README* - template/* + - dependency.png changelog: sort: asc diff --git a/README.md b/README.md index 1951961..9872beb 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,12 @@ [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/spiegel-im-spiegel/books-data/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/spiegel-im-spiegel/books-data.svg)](https://github.com/spiegel-im-spiegel/books-data/releases/latest) -## Download and Build +This package is required Go 1.16 or later. + +## Build and Install ``` -$ go get github.com/spiegel-im-spiegel/books-data@latest +$ go install github.com/spiegel-im-spiegel/books-data@latest ``` ### Binaries @@ -403,6 +405,10 @@ $ books-data history -i 9784274069321 -t testdata/review-template/template.html ``` +## Modules Requirement Graph + +[![dependency.png](./dependency.png)](./dependency.png) + ## Reference - [DDRBoxman/go-amazon-product-api: Wrapper for the Amazon Product Advertising API](https://github.com/DDRBoxman/go-amazon-product-api) diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..b3088f0 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,50 @@ +version: '3' + +tasks: + default: + cmds: + - task: clean + - task: test + - task: nancy + - task: graph + + build-all: + desc: Build executable binary with GoReleaser. + cmds: + - goreleaser --snapshot --skip-publish --rm-dist + + test: + desc: Test and lint. + cmds: + - go mod verify + - go test ./... + - docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.40.1 golangci-lint run --enable gosec --timeout 3m0s ./... + sources: + - ./go.mod + - '**/*.go' + + nancy: + desc: Check vulnerability of external packages with Nancy. + cmds: + - depm list -j | docker run --rm -i sonatypecommunity/nancy:latest sleuth -n + sources: + - ./go.mod + - '**/*.go' + + clean: + desc: Initialize module and build cache, and remake go.sum file. + cmds: + - rm -f ./go.sum + - go clean -cache + - go clean -modcache + - go mod tidy -v + + graph: + desc: Make grapth of dependency modules. + cmds: + - depm m --dot --dot-config dot-config.toml | dot -Tpng -o ./dependency.png + sources: + - ./go.mod + - '**/*.go' + generates: + - ./dependency.png diff --git a/api/aozoraapi/aozoraapi.go b/api/aozoraapi/aozoraapi.go index a478c31..130ab92 100644 --- a/api/aozoraapi/aozoraapi.go +++ b/api/aozoraapi/aozoraapi.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "net/http" "strconv" "github.com/spiegel-im-spiegel/aozora-api" @@ -19,14 +18,13 @@ import ( type AozoraAPI struct { svcType api.ServiceType //Service Type server *aozora.Server //server info. - ctx context.Context //context } var _ api.API = (*AozoraAPI)(nil) //AozoraAPI is compatible with api.API interface //New returns OpenBD instance -func New(ctx context.Context) *AozoraAPI { - return &AozoraAPI{svcType: api.TypeAozoraAPI, server: aozora.New(), ctx: ctx} +func New() *AozoraAPI { + return &AozoraAPI{svcType: api.TypeAozoraAPI, server: aozora.New()} } //Name returns name of API @@ -35,7 +33,7 @@ func (a *AozoraAPI) Name() string { } //LookupRawData returns openBD raw data -func (a *AozoraAPI) LookupRawData(id string) (io.Reader, error) { +func (a *AozoraAPI) LookupRawData(ctx context.Context, id string) (io.Reader, error) { bookId, err := strconv.Atoi(id) if err != nil { return nil, errs.New( @@ -43,7 +41,7 @@ func (a *AozoraAPI) LookupRawData(id string) (io.Reader, error) { errs.WithContext("id", id), ) } - b, err := a.server.CreateClient(aozora.WithContext(a.ctx), aozora.WithHttpClient(&http.Client{})).LookupBookRaw(bookId) + b, err := a.server.CreateClient().LookupBookRawContext(ctx, bookId) if err != nil { return nil, errs.Wrap(err, errs.WithContext("id", id)) } @@ -51,7 +49,7 @@ func (a *AozoraAPI) LookupRawData(id string) (io.Reader, error) { } //LookupBook returns Book data from openBD -func (a *AozoraAPI) LookupBook(id string) (*entity.Book, error) { +func (a *AozoraAPI) LookupBook(ctx context.Context, id string) (*entity.Book, error) { bookId, err := strconv.Atoi(id) if err != nil { return nil, errs.New( @@ -60,7 +58,7 @@ func (a *AozoraAPI) LookupBook(id string) (*entity.Book, error) { errs.WithContext("id", id), ) } - bk, err := a.server.CreateClient(aozora.WithContext(a.ctx), aozora.WithHttpClient(&http.Client{})).LookupBook(bookId) + bk, err := a.server.CreateClient().LookupBookContext(ctx, bookId) if err != nil { return nil, errs.Wrap(err, errs.WithContext("id", id)) } @@ -73,7 +71,7 @@ func (a *AozoraAPI) LookupBook(id string) (*entity.Book, error) { OriginalTitle: bk.OriginalTitle, URL: bk.CardURL, ProductType: "青空文庫", - Codes: []entity.Code{entity.Code{Name: "図書カードNo.", Value: strconv.Itoa(bk.BookID)}}, + Codes: []entity.Code{{Name: "図書カードNo.", Value: strconv.Itoa(bk.BookID)}}, Creators: getCreators(bk), PublicationDate: values.NewDate(bk.ReleaseDate.Time), LastRelease: values.NewDate(bk.LastModified.Time), @@ -103,7 +101,7 @@ func getCreators(bk *aozora.Book) []entity.Creator { return creators } -/* Copyright 2019,2020 Spiegel +/* Copyright 2019-2021 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/api.go b/api/api.go index c4376ba..efcb49c 100644 --- a/api/api.go +++ b/api/api.go @@ -1,6 +1,7 @@ package api import ( + "context" "io" "github.com/spiegel-im-spiegel/books-data/entity" @@ -8,9 +9,9 @@ import ( //API is interface class for searching book API type API interface { - Name() string //Name of API - LookupBook(id string) (*entity.Book, error) //Lookup book data by API - LookupRawData(id string) (io.Reader, error) //Lookup raw data by API + Name() string //Name of API + LookupBook(ctx context.Context, id string) (*entity.Book, error) //Lookup book data by API + LookupRawData(ctx context.Context, id string) (io.Reader, error) //Lookup raw data by API } /* Copyright 2019 Spiegel diff --git a/api/openbd/openbd.go b/api/openbd/openbd.go index b427865..aee85d1 100644 --- a/api/openbd/openbd.go +++ b/api/openbd/openbd.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "net/http" "github.com/spiegel-im-spiegel/books-data/api" "github.com/spiegel-im-spiegel/books-data/ecode" @@ -20,14 +19,13 @@ import ( type OpenBD struct { svcType api.ServiceType //Service Type server *obd.Server //server info. - ctx context.Context //context } var _ api.API = (*OpenBD)(nil) //OpenBD is compatible with api.API interface //New returns OpenBD instance -func New(ctx context.Context) *OpenBD { - return &OpenBD{svcType: api.TypeOpenBD, server: obd.New(), ctx: ctx} +func New() *OpenBD { + return &OpenBD{svcType: api.TypeOpenBD, server: obd.New()} } //Name returns name of API @@ -36,8 +34,8 @@ func (a *OpenBD) Name() string { } ///LookupRawData returns openBD raw data -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}) +func (a *OpenBD) LookupRawData(ctx context.Context, id string) (io.Reader, error) { + res, err := a.server.CreateClient().LookupBooksRawContext(ctx, []string{id}) if err != nil { return nil, errs.New( fmt.Sprintf("invalid book id: %v", id), @@ -49,8 +47,8 @@ func (a *OpenBD) LookupRawData(id string) (io.Reader, error) { } ///LookupBook returns Book data from openBD -func (a *OpenBD) LookupBook(id string) (*entity.Book, error) { - data, err := a.LookupRawData(id) +func (a *OpenBD) LookupBook(ctx context.Context, id string) (*entity.Book, error) { + data, err := a.LookupRawData(ctx, id) if err != nil { return nil, errs.Wrap(err, errs.WithContext("id", id)) } @@ -71,7 +69,7 @@ func (a *OpenBD) LookupBook(id string) (*entity.Book, error) { URL: bd.ImageURL(), }, ProductType: "Book", - Codes: []entity.Code{entity.Code{Name: "ISBN", Value: bd.ISBN()}}, + Codes: []entity.Code{{Name: "ISBN", Value: bd.ISBN()}}, Creators: getCreators(bd), Publisher: bd.Publisher(), PublicationDate: values.NewDate(bd.PublicationDate().Time), @@ -104,7 +102,7 @@ func unmarshalJSON(jsondata io.Reader) (*obd.Book, error) { return &books[0], nil } -/* Copyright 2019,2020 Spiegel +/* Copyright 2019-2021 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 92ed1c1..ab351f8 100644 --- a/api/pa/entity.go +++ b/api/pa/entity.go @@ -134,7 +134,7 @@ func (i *Item) ProductType() string { } func (i *Item) Codes() []entity.Code { - codes := []entity.Code{entity.Code{Name: "ASIN", Value: i.ASIN}} + codes := []entity.Code{{Name: "ASIN", Value: i.ASIN}} if i.ItemInfo != nil && i.ItemInfo.ExternalIds != nil { ids := i.ItemInfo.ExternalIds.EANs if ids != nil { @@ -255,7 +255,7 @@ func (r *Response) String() string { return string(b) } -/* Copyright 2019,2020 Spiegel +/* Copyright 2019-2021 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 93c96c6..d302a25 100644 --- a/api/pa/paapi5.go +++ b/api/pa/paapi5.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "io" - "net/http" "github.com/spiegel-im-spiegel/books-data/api" "github.com/spiegel-im-spiegel/books-data/entity" @@ -19,21 +18,19 @@ type PAAPI5 struct { associateTag string accessKey string secretKey string - server *paapi5.Server //server info. - ctx context.Context //context + server *paapi5.Server //server info. } var _ api.API = (*PAAPI5)(nil) //PAAPI5 is compatible with api.API interface //New returns PaAPI instance -func New(ctx context.Context, marketplace, associateTag, accessKey, secretKey string) *PAAPI5 { +func New(marketplace, associateTag, accessKey, secretKey string) *PAAPI5 { return &PAAPI5{ svcType: api.TypePAAPI, associateTag: associateTag, accessKey: accessKey, secretKey: secretKey, server: paapi5.New(paapi5.WithMarketplace(paapi5.MarketplaceOf(marketplace))), - ctx: ctx, } } @@ -43,16 +40,14 @@ func (a *PAAPI5) Name() string { } ///LookupRawData returns PA-API raw data -func (a *PAAPI5) LookupRawData(id string) (io.Reader, error) { +func (a *PAAPI5) LookupRawData(ctx context.Context, id string) (io.Reader, error) { client := a.server.CreateClient( a.associateTag, a.accessKey, a.secretKey, - paapi5.WithContext(a.ctx), - paapi5.WithHttpClient(&http.Client{}), ) q := NewQuery(client.Marketplace(), client.PartnerTag(), client.PartnerType(), []string{id}) - body, err := client.Request(q) + body, err := client.RequestContext(ctx, q) if err != nil { return nil, errs.Wrap(err, errs.WithContext("id", id)) } @@ -61,8 +56,8 @@ func (a *PAAPI5) LookupRawData(id string) (io.Reader, error) { } ///LookupBook returns Book data from PA-API -func (a *PAAPI5) LookupBook(id string) (*entity.Book, error) { - r, err := a.LookupRawData(id) +func (a *PAAPI5) LookupBook(ctx context.Context, id string) (*entity.Book, error) { + r, err := a.LookupRawData(ctx, id) if err != nil { return nil, errs.Wrap(err, errs.WithContext("id", id)) } @@ -74,7 +69,7 @@ func (a *PAAPI5) LookupBook(id string) (*entity.Book, error) { return book, errs.Wrap(err, errs.WithContext("id", id)) } -/* Copyright 2019,2020 Spiegel +/* Copyright 2019-2021 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/clean-all.sh b/clean-all.sh deleted file mode 100755 index 53c80b5..0000000 --- a/clean-all.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -rm ./go.sum -go clean -cache -go clean -modcache diff --git a/dependency.png b/dependency.png new file mode 100644 index 0000000..d7d7050 Binary files /dev/null and b/dependency.png differ diff --git a/dot-config.toml b/dot-config.toml new file mode 100644 index 0000000..a767d55 --- /dev/null +++ b/dot-config.toml @@ -0,0 +1,4 @@ +[node] + fontname = "Inconsolata" +[edge] + color = "red" diff --git a/facade/aozora.go b/facade/aozora.go index cd0c675..32ce9e7 100644 --- a/facade/aozora.go +++ b/facade/aozora.go @@ -10,11 +10,10 @@ import ( ) func searchAozoraAPI(ctx context.Context, id string, rawFlag bool) (io.Reader, error) { - aozora := aozoraapi.New(ctx) if rawFlag { - return aozora.LookupRawData(id) + return aozoraapi.New().LookupRawData(ctx, id) } - book, err := aozora.LookupBook(id) + book, err := aozoraapi.New().LookupBook(ctx, id) if err != nil { return nil, err } @@ -26,10 +25,10 @@ func searchAozoraAPI(ctx context.Context, id string, rawFlag bool) (io.Reader, e } func findAozoraAPI(ctx context.Context, id string) (*entity.Book, error) { - return aozoraapi.New(ctx).LookupBook(id) + return aozoraapi.New().LookupBook(ctx, id) } -/* Copyright 2019 Spiegel +/* Copyright 2019-2021 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/openbd.go b/facade/openbd.go index 25ee614..b6bbd94 100644 --- a/facade/openbd.go +++ b/facade/openbd.go @@ -10,11 +10,10 @@ import ( ) func searchOpenBD(ctx context.Context, id string, rawFlag bool) (io.Reader, error) { - obdapi := openbd.New(ctx) if rawFlag { - return obdapi.LookupRawData(id) + return openbd.New().LookupRawData(ctx, id) } - book, err := obdapi.LookupBook(id) + book, err := openbd.New().LookupBook(ctx, id) if err != nil { return nil, err } @@ -26,10 +25,10 @@ func searchOpenBD(ctx context.Context, id string, rawFlag bool) (io.Reader, erro } func findOpenBD(ctx context.Context, id string) (*entity.Book, error) { - return openbd.New(ctx).LookupBook(id) + return openbd.New().LookupBook(ctx, id) } -/* Copyright 2019 Spiegel +/* Copyright 2019-2021 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 5a245e5..f1fe499 100644 --- a/facade/paapi.go +++ b/facade/paapi.go @@ -41,9 +41,8 @@ func getPaapiParams() (*paapiParams, error) { return &paapiParams{marketplace: marketplace, associateTag: associateTag, accessKey: accessKey, secretKey: secretKey}, nil } -func createPAAPI(ctx context.Context, p *paapiParams) api.API { +func createPAAPI(p *paapiParams) api.API { return pa.New( - ctx, p.marketplace, p.associateTag, p.accessKey, @@ -53,9 +52,9 @@ func createPAAPI(ctx context.Context, p *paapiParams) api.API { func searchPAAPI(ctx context.Context, id string, p *paapiParams, rawFlag bool) (io.Reader, error) { if rawFlag { - return createPAAPI(ctx, p).LookupRawData(id) + return createPAAPI(p).LookupRawData(ctx, id) } - book, err := createPAAPI(ctx, p).LookupBook(id) + book, err := createPAAPI(p).LookupBook(ctx, id) if err != nil { return nil, errs.Wrap(err, errs.WithContext("id", id)) } @@ -67,10 +66,10 @@ func searchPAAPI(ctx context.Context, id string, p *paapiParams, rawFlag bool) ( } func findPAAPI(ctx context.Context, id string, p *paapiParams) (*entity.Book, error) { - return createPAAPI(ctx, p).LookupBook(id) + return createPAAPI(p).LookupBook(ctx, id) } -/* Copyright 2019,2020 Spiegel +/* Copyright 2019-2021 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 4a5b5cb..2b6b162 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,15 @@ module github.com/spiegel-im-spiegel/books-data -go 1.15 +go 1.16 require ( - github.com/spf13/cobra v1.0.1-0.20201001152800-40d34bca1bff + github.com/spf13/cobra v1.1.3 github.com/spf13/viper v1.7.1 - github.com/spiegel-im-spiegel/aozora-api v0.2.6 + github.com/spiegel-im-spiegel/aozora-api v0.3.0 github.com/spiegel-im-spiegel/errs v1.0.2 - github.com/spiegel-im-spiegel/gocli v0.10.3 - github.com/spiegel-im-spiegel/openbd-api v0.2.6 - github.com/spiegel-im-spiegel/pa-api v0.7.2 - golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect + github.com/spiegel-im-spiegel/gocli v0.10.4 + github.com/spiegel-im-spiegel/openbd-api v0.3.0 + github.com/spiegel-im-spiegel/pa-api v0.9.0 ) -replace github.com/coreos/etcd v3.3.13+incompatible => github.com/coreos/etcd v3.3.25+incompatible +replace golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 => golang.org/x/sys v0.0.0-20210521090106-6ca3eb03dfc2 diff --git a/go.sum b/go.sum index c0c2cee..8c2cbda 100644 --- a/go.sum +++ b/go.sum @@ -27,7 +27,7 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 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.25+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.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= @@ -163,8 +163,8 @@ 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 v1.0.1-0.20201001152800-40d34bca1bff h1:lXHkF95Duj/nGE2mY+kNS5DJX5OJ04jO7WA6zCqrp/0= -github.com/spf13/cobra v1.0.1-0.20201001152800-40d34bca1bff/go.mod h1:yk5b0mALVusDL5fMM6Rd1wgnoO5jUPhwsQ6LQAJTidQ= +github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= +github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= 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/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= @@ -173,16 +173,18 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= -github.com/spiegel-im-spiegel/aozora-api v0.2.6 h1:U7tnnBx2MGND6kVFdFnvf34BJyUUemjSHLlMRtW/KlA= -github.com/spiegel-im-spiegel/aozora-api v0.2.6/go.mod h1:qWT6b+x6hpFeGvN9r2gZRQ9kBYvlzNoDHmaD73poCH0= +github.com/spiegel-im-spiegel/aozora-api v0.3.0 h1:VRUKY0XYkiJ8EcN/97Vv5Xu7fZBskRKC37Sn19JfNEM= +github.com/spiegel-im-spiegel/aozora-api v0.3.0/go.mod h1:Gzmim5/QYWOqU4Nmti+THH39AxJ1yzEatKj9065JBz8= github.com/spiegel-im-spiegel/errs v1.0.2 h1:v4amEwRDqRWjKHOILQnJSovYhZ4ZttEnBBXNXEzS6Sc= github.com/spiegel-im-spiegel/errs v1.0.2/go.mod h1:UoasJYYujMcdkbT9USv8dfZWoMyaY3btqQxoLJImw0A= -github.com/spiegel-im-spiegel/gocli v0.10.3 h1:+9V71Tl3ELjNEsEcXVSZKxJHaiTC55mVsPQwrZq8AAc= -github.com/spiegel-im-spiegel/gocli v0.10.3/go.mod h1:9vRvly2giutJ2sAtQjrw570p9ulJA3twgKlurmnj12g= -github.com/spiegel-im-spiegel/openbd-api v0.2.6 h1:4hpcfNPlF3tZmeVKwnbsUs9KEXyUGvltUDhMKFmVftE= -github.com/spiegel-im-spiegel/openbd-api v0.2.6/go.mod h1:FqVoZkWltWw7/R4EewubQoLFd2dfRRmg6RmnmM/YTmY= -github.com/spiegel-im-spiegel/pa-api v0.7.2 h1:9l++1a61k68RaoNSQIYQGCIh2F5DaJzxsYKcb/ahHms= -github.com/spiegel-im-spiegel/pa-api v0.7.2/go.mod h1:NqvGh1mER0rAAHIFgmO0ri/6VXSedi2VrLke3oVQul8= +github.com/spiegel-im-spiegel/fetch v0.2.3 h1:Zh5rHvOjfC81rxKvtUD21JT609smds+BRh+H84s8qEw= +github.com/spiegel-im-spiegel/fetch v0.2.3/go.mod h1:ePIXxdC9OvSarXEO6HW1MgQwtBaKQo0qgDLOhKFXkQ0= +github.com/spiegel-im-spiegel/gocli v0.10.4 h1:aoAWdiQ4hjNxmEod4EeTZTcjdCJcrNOwgHBs5BQYnEQ= +github.com/spiegel-im-spiegel/gocli v0.10.4/go.mod h1:ffI3zoggRyLOZ+IIgaVN8WVMUwfIwfvCEd/0Yl/PZ98= +github.com/spiegel-im-spiegel/openbd-api v0.3.0 h1:CUXN49IViwajAkdv36SY9Ozkrh5oeoJRpMm9Q40tyM8= +github.com/spiegel-im-spiegel/openbd-api v0.3.0/go.mod h1:iX7B/fHcp9585JYae9hiHinjNRTC4rhXh83CTE3c4IY= +github.com/spiegel-im-spiegel/pa-api v0.9.0 h1:xbrPJDAbDf0dzYu7BRfIr0pdHQDYpvsQmcjitpaOxP8= +github.com/spiegel-im-spiegel/pa-api v0.9.0/go.mod h1:DYAuXUPAi1xrNroBybPo/JIzPXo3VCAF/33mEJgf9hU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 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= @@ -255,9 +257,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210521090106-6ca3eb03dfc2 h1:48AqIJLs69Wmc3mA52aIcqt544rjrDCqolKAv7L8leA= +golang.org/x/sys v0.0.0-20210521090106-6ca3eb03dfc2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -314,8 +315,8 @@ gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/review/api_test.go b/review/api_test.go index 889dcd5..f97474b 100644 --- a/review/api_test.go +++ b/review/api_test.go @@ -2,6 +2,7 @@ package review import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -23,12 +24,12 @@ func (ta testAPI) Name() string { return "test" } -func (ta testAPI) LookupRawData(id string) (io.Reader, error) { +func (ta testAPI) LookupRawData(ctx context.Context, id string) (io.Reader, error) { return bytes.NewBufferString(ta.output), nil } -func (ta testAPI) LookupBook(id string) (*entity.Book, error) { - r, _ := ta.LookupRawData(id) +func (ta testAPI) LookupBook(ctx context.Context, id string) (*entity.Book, error) { + r, _ := ta.LookupRawData(ctx, id) dec := json.NewDecoder(r) books := &entity.Book{} if err := dec.Decode(books); err != nil { @@ -78,7 +79,7 @@ var ( func TestAPI(t *testing.T) { tc := NewTestAPI() - book, err := tc.LookupBook("card56642") + book, err := tc.LookupBook(context.Background(), "card56642") if err != nil { t.Errorf("testAPI.LookupBook() error is \"%v\", want nil", err) fmt.Printf("Info: %+v\n", err) @@ -90,7 +91,7 @@ func TestAPI(t *testing.T) { } } -/* Copyright 2019 Spiegel +/* Copyright 2019-2021 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_test.go b/review/review_test.go index 6567690..0280db5 100644 --- a/review/review_test.go +++ b/review/review_test.go @@ -1,6 +1,7 @@ package review import ( + "context" "fmt" "testing" ) @@ -8,7 +9,7 @@ import ( func TestReview(t *testing.T) { res := `{"Book":` + testBookResp + `,"Date":"2019-01-01","Rating":4,"Star":[true,true,true,true,false],"Description":"実はちゃんと読んでない(笑) 学生時代に読んでおけばよかった。"}` tc := NewTestAPI() - book, err := tc.LookupBook("card56642") + book, err := tc.LookupBook(context.Background(), "card56642") if err != nil { t.Errorf("testAPI.LookupBook() error is \"%v\", want nil", err) fmt.Printf("Info: %+v\n", err) @@ -48,7 +49,7 @@ var formattedText = `