Skip to content

Commit

Permalink
Merge pull request #8 from spiegel-im-spiegel/fix-bugs-and-testing
Browse files Browse the repository at this point in the history
Bump up version of external packages
  • Loading branch information
spiegel-im-spiegel committed May 22, 2021
2 parents fae2d20 + ba859c9 commit 0197bec
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
6 changes: 4 additions & 2 deletions .github/workflows/vulns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
# Other files and folders
*.bak
dist/
.task/
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -43,6 +43,7 @@ archives:
- LICENSE*
- README*
- template/*
- dependency.png

changelog:
sort: asc
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -403,6 +405,10 @@ $ books-data history -i 9784274069321 -t testdata/review-template/template.html
</div>
```

## 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)
Expand Down
50 changes: 50 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 8 additions & 10 deletions api/aozoraapi/aozoraapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"net/http"
"strconv"

"github.com/spiegel-im-spiegel/aozora-api"
Expand All @@ -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
Expand All @@ -35,23 +33,23 @@ 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(
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)
b, err := a.server.CreateClient().LookupBookRawContext(ctx, bookId)
if err != nil {
return nil, errs.Wrap(err, errs.WithContext("id", id))
}
return bytes.NewReader(b), nil
}

//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(
Expand All @@ -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))
}
Expand All @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package api

import (
"context"
"io"

"github.com/spiegel-im-spiegel/books-data/entity"
)

//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
Expand Down
18 changes: 8 additions & 10 deletions api/openbd/openbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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),
Expand All @@ -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))
}
Expand All @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions api/pa/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 0197bec

Please sign in to comment.