Skip to content

Commit

Permalink
Update support Go version
Browse files Browse the repository at this point in the history
  • Loading branch information
osamingo committed Oct 7, 2022
1 parent 15b4b0e commit 56e0be8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ jobs:
name: Lint
runs-on: ubuntu-18.04
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.17
- uses: actions/checkout@v3
- uses: golangci/golangci-lint-action@v3
with:
version: v1.44.2
version: v1.49.0
test:
name: Test
runs-on: ubuntu-18.04
strategy:
matrix:
go: [ '1.16.x', '1.17.x', '1.18.x' ]
go: [ '1.18.x', '1.19.x' ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v2
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ issues:
- ifshort
- varnamelen
- containedctx
- nosnakecase
- exhaustruct
8 changes: 3 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -55,8 +54,7 @@ func NewClient(token string, opts ...ClientOption) (*Client, error) {
return cli, nil
}

// nolint: cyclop
func (cli *Client) sendRequest(req *http.Request, res interface{}) error {
func (cli *Client) sendRequest(req *http.Request, res interface{}) error { //nolint: cyclop
req.Header.Add("Authorization", "token "+cli.token)

resp, err := cli.HTTPClient.Do(req)
Expand All @@ -69,7 +67,7 @@ func (cli *Client) sendRequest(req *http.Request, res interface{}) error {
}

defer func() {
_, _ = io.Copy(ioutil.Discard, resp.Body)
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
}()

Expand All @@ -91,7 +89,7 @@ func (cli *Client) sendRequest(req *http.Request, res interface{}) error {
case http.StatusInternalServerError:
return ErrInternalServerError
default:
// nolint: goerr113
//nolint: goerr113
return fmt.Errorf("kenall: not registered in the error handling, http status code = %d", resp.StatusCode)
}

Expand Down
34 changes: 17 additions & 17 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestClient_GetAddress(t *testing.T) {
ctx context.Context
postalCode string
checkAsError bool
wantError error
wantError any
wantJISX0402 string
}{
"Normal case": {endpoint: srv.URL, token: "opencollector", ctx: context.Background(), postalCode: "1008105", checkAsError: false, wantError: nil, wantJISX0402: "13104"},
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestClient_GetAddress(t *testing.T) {
res, err := cli.GetAddress(c.ctx, c.postalCode)
if c.checkAsError && !errors.As(err, &c.wantError) {
t.Errorf("give: %v, want: %v", err, c.wantError)
} else if !errors.Is(err, c.wantError) {
} else if want, _ := c.wantError.(error); !errors.Is(err, want) {
t.Errorf("give: %v, want: %v", err, c.wantError)
}
if res != nil && res.Addresses[0].JISX0402 != c.wantJISX0402 {
Expand All @@ -150,7 +150,7 @@ func TestClient_GetCity(t *testing.T) {
ctx context.Context
prefectureCode string
checkAsError bool
wantError error
wantError any
wantJISX0402 string
}{
"Normal case": {endpoint: srv.URL, token: "opencollector", ctx: context.Background(), prefectureCode: "13", checkAsError: false, wantError: nil, wantJISX0402: "13101"},
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestClient_GetCity(t *testing.T) {
res, err := cli.GetCity(c.ctx, c.prefectureCode)
if c.checkAsError && !errors.As(err, &c.wantError) {
t.Errorf("give: %v, want: %v", err, c.wantError)
} else if !errors.Is(err, c.wantError) {
} else if want, _ := c.wantError.(error); !errors.Is(err, want) {
t.Errorf("give: %v, want: %v", err, c.wantError)
}
if res != nil && res.Cities[0].JISX0402 != c.wantJISX0402 {
Expand All @@ -208,7 +208,7 @@ func TestClient_GetCorporation(t *testing.T) {
ctx context.Context
corporateNumber string
checkAsError bool
wantError error
wantError any
wantJISX0402 string
}{
"Normal case": {endpoint: srv.URL, token: "opencollector", ctx: context.Background(), corporateNumber: "2021001052596", checkAsError: false, wantError: nil, wantJISX0402: "13101"},
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestClient_GetCorporation(t *testing.T) {
res, err := cli.GetCorporation(c.ctx, c.corporateNumber)
if c.checkAsError && !errors.As(err, &c.wantError) {
t.Errorf("give: %v, want: %v", err, c.wantError)
} else if !errors.Is(err, c.wantError) {
} else if want, _ := c.wantError.(error); !errors.Is(err, want) {
t.Errorf("give: %v, want: %v", err, c.wantError)
}
if res != nil && res.Corporation.JISX0402 != c.wantJISX0402 {
Expand All @@ -265,7 +265,7 @@ func TestClient_GetWhoami(t *testing.T) {
token string
ctx context.Context
checkAsError bool
wantError error
wantError any
wantAddr string
}{
"Normal case": {endpoint: srv.URL, token: "opencollector", ctx: context.Background(), checkAsError: false, wantError: nil, wantAddr: "192.168.0.1"},
Expand All @@ -289,7 +289,7 @@ func TestClient_GetWhoami(t *testing.T) {
res, err := cli.GetWhoami(c.ctx)
if c.checkAsError && !errors.As(err, &c.wantError) {
t.Errorf("give: %v, want: %v", err, c.wantError)
} else if !errors.Is(err, c.wantError) {
} else if want, _ := c.wantError.(error); !errors.Is(err, want) {
t.Errorf("give: %v, want: %v", err, c.wantError)
}
if res != nil && res.RemoteAddress.String() != c.wantAddr {
Expand All @@ -314,7 +314,7 @@ func TestClient_GetHolidays(t *testing.T) {
token string
ctx context.Context
checkAsError bool
wantError error
wantError any
wantTitle string
}{
"Normal case": {endpoint: srv.URL, token: "opencollector", ctx: context.Background(), checkAsError: false, wantError: nil, wantTitle: "元日"},
Expand All @@ -338,7 +338,7 @@ func TestClient_GetHolidays(t *testing.T) {
res, err := cli.GetHolidays(c.ctx)
if c.checkAsError && !errors.As(err, &c.wantError) {
t.Errorf("give: %v, want: %v", err, c.wantError)
} else if !errors.Is(err, c.wantError) {
} else if want, _ := c.wantError.(error); !errors.Is(err, want) {
t.Errorf("give: %v, want: %v", err, c.wantError)
}
if res != nil && res.Holidays[0].Title != c.wantTitle {
Expand All @@ -364,7 +364,7 @@ func TestClient_GetHolidaysByYear(t *testing.T) {
ctx context.Context
giveYear int
checkAsError bool
wantError error
wantError any
wantLen int
}{
"Normal case": {endpoint: srv.URL, token: "opencollector", ctx: context.Background(), giveYear: 2022, checkAsError: false, wantError: nil, wantLen: 16},
Expand All @@ -389,7 +389,7 @@ func TestClient_GetHolidaysByYear(t *testing.T) {
res, err := cli.GetHolidaysByYear(c.ctx, c.giveYear)
if c.checkAsError && !errors.As(err, &c.wantError) {
t.Errorf("give: %v, want: %v", err, c.wantError)
} else if !errors.Is(err, c.wantError) {
} else if want, _ := c.wantError.(error); !errors.Is(err, want) {
t.Errorf("give: %v, want: %v", err, c.wantError)
}
if res != nil && len(res.Holidays) != c.wantLen {
Expand Down Expand Up @@ -426,7 +426,7 @@ func TestClient_GetHolidaysByPeriod(t *testing.T) {
giveFrom time.Time
giveTo time.Time
checkAsError bool
wantError error
wantError any
wantLen int
}{
"Normal case": {endpoint: srv.URL, token: "opencollector", ctx: context.Background(), giveFrom: from, giveTo: to, checkAsError: false, wantError: nil, wantLen: 16},
Expand All @@ -451,7 +451,7 @@ func TestClient_GetHolidaysByPeriod(t *testing.T) {
res, err := cli.GetHolidaysByPeriod(c.ctx, c.giveFrom, c.giveTo)
if c.checkAsError && !errors.As(err, &c.wantError) {
t.Errorf("give: %v, want: %v", err, c.wantError)
} else if !errors.Is(err, c.wantError) {
} else if want, _ := c.wantError.(error); !errors.Is(err, want) {
t.Errorf("give: %v, want: %v", err, c.wantError)
}
if res != nil && len(res.Holidays) != c.wantLen {
Expand All @@ -475,7 +475,7 @@ func TestClient_GetNormalizeAddress(t *testing.T) {
ctx context.Context
giveAddress string
checkAsError bool
wantError error
wantError any
wantBlockLotNum string
}{
"Normal case": {endpoint: srv.URL, token: "opencollector", ctx: context.Background(), giveAddress: "東京都港区六本木六丁目10番1号六本木ヒルズ森タワー18F", checkAsError: false, wantError: nil, wantBlockLotNum: "6-10-1"},
Expand All @@ -498,7 +498,7 @@ func TestClient_GetNormalizeAddress(t *testing.T) {
res, err := cli.GetNormalizeAddress(c.ctx, c.giveAddress)
if c.checkAsError && !errors.As(err, &c.wantError) {
t.Errorf("give: %v, want: %v", err, c.wantError)
} else if !errors.Is(err, c.wantError) {
} else if want, _ := c.wantError.(error); !errors.Is(err, want) {
t.Errorf("give: %v, want: %v", err, c.wantError)
}
if res != nil && res.Query.BlockLotNum.String != c.wantBlockLotNum {
Expand Down Expand Up @@ -699,7 +699,7 @@ func handlePostalAPI(t *testing.T, w http.ResponseWriter, uri string) {
t.Helper()

if strings.HasPrefix(uri, "/postalcode/?") {
// nolint: errcheck
//nolint: errcheck
u, _ := url.Parse(uri)

switch u.Query().Get("t") {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/osamingo/go-kenall/v2

go 1.17
go 1.18
8 changes: 4 additions & 4 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ type (
)

var (
// nolint: gochecknoglobals
//nolint: gochecknoglobals
nullLiteral = []byte("null")
// nolint: gochecknoglobals, gomnd
//nolint: gochecknoglobals, gomnd
jst = time.FixedZone("Asia/Tokyo", 9*60*60)

_ json.Unmarshaler = (*Version)(nil)
Expand Down Expand Up @@ -200,7 +200,7 @@ func (ra *RemoteAddress) UnmarshalJSON(data []byte) error {
return fmt.Errorf("kenall: failed to resolve IP address: %w", err)
}
default:
// nolint: goerr113
//nolint: goerr113
return errors.New("kenall: undefined type of RemoteAddress, type = " + tmp.Type)
}

Expand Down Expand Up @@ -236,7 +236,7 @@ func (h *Holiday) UnmarshalJSON(data []byte) error {

// MarshalJSON implements json.Marshaler interface.
func (h Holiday) MarshalJSON() ([]byte, error) {
// nolint: wrapcheck
//nolint: wrapcheck
return json.Marshal(&holiday{
Title: h.Title,
Date: h.Format(RFC3339DateFormat),
Expand Down

0 comments on commit 56e0be8

Please sign in to comment.