Skip to content

Commit

Permalink
mod: upgrade go to 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
veezhang committed Aug 8, 2022
1 parent c5edb99 commit 117be88
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Unit Tests
strategy:
matrix:
go-version: [1.17.x]
go-version: [1.17.x,1.18.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
23 changes: 5 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,19 @@ tools: $(GOBIN)/goimports \
$(GOBIN)/mockgen

$(GOBIN)/goimports:
$(call go-get-tool,$(GOBIN)/goimports,golang.org/x/tools/cmd/goimports)
go install golang.org/x/tools/cmd/goimports@v0.1.12

$(GOBIN)/impi:
$(call go-get-tool,$(GOBIN)/impi,github.com/pavius/impi/cmd/impi)
go install github.com/pavius/impi/cmd/impi@v0.0.3

$(GOBIN)/gofumpt:
$(call go-get-tool,$(GOBIN)/gofumpt,mvdan.cc/gofumpt)
go install mvdan.cc/gofumpt@v0.3.1

$(GOBIN)/golangci-lint:
@[ -f $(GOBIN)/golangci-lint ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.42.0 ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.48.0 ;\
}

$(GOBIN)/mockgen:
$(call go-get-tool,$(GOBIN)/mockgen,github.com/golang/mock/[email protected])

# go-get-tool will 'go get' any package $2 and install it to $1.
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
go install github.com/golang/mock/[email protected]
13 changes: 7 additions & 6 deletions errorx/errorx.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ func SetCodeCombiner(combiner CodeCombiner) {
// WithCode return error warps with codeError.
// c is the code. err is the real err. formatWithArgs is details with format string including args.
// For example:
// WithCode(ErrBadRequest, nil)
// WithCode(ErrBadRequest, err)
// WithCode(ErrBadRequest, err, "details")
// WithCode(ErrBadRequest, err, "details %s", "id")
//
// WithCode(ErrBadRequest, nil)
// WithCode(ErrBadRequest, err)
// WithCode(ErrBadRequest, err, "details")
// WithCode(ErrBadRequest, err, "details %s", "id")
func WithCode(c *ErrCode, err error, formatWithArgs ...interface{}) error {
ce := &codeError{
error: err,
Expand Down Expand Up @@ -264,9 +265,9 @@ func callers() *stack {
}

func (s *stack) Format(st fmt.State, verb rune) {
switch verb { // nolint:gocritic,revive
switch verb { //nolint:gocritic,revive
case 'v':
switch { // nolint:gocritic,revive
switch { //nolint:gocritic,revive
case st.Flag('+'):
for _, pc := range *s {
f := errors.Frame(pc)
Expand Down
2 changes: 1 addition & 1 deletion errorx/errorx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestWithCode(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
err := WithCode(test.code, test.err, test.args...)
assert.Equal(t, test.expectedErrStr, err.Error())
assert.Equal(t, fmt.Sprintf("%v", err), test.expectedErrStr)
assert.Equal(t, fmt.Sprintf("%v", err), test.expectedErrStr) //nolint:gocritic
assert.Equal(t, fmt.Sprintf("%q", err), fmt.Sprintf("%q", test.expectedErrStr))
stackCount := strings.Count(fmt.Sprintf("%+v", err), "errorx.TestWithCode")
assert.Equal(t, 1, stackCount)
Expand Down
4 changes: 2 additions & 2 deletions httpclient/bytes_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package httpclient

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestBytesClient(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ast.Equal(method, r.Method)
if r.Method != resty.MethodGet {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
ast.NoError(err)
ast.Equal(reqBody, body)
}
Expand Down
4 changes: 2 additions & 2 deletions httpclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package httpclient

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestClient(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ast.Equal(method, r.Method)
if r.Method != resty.MethodGet {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
ast.NoError(err)
ast.Equal(reqBody, body)
}
Expand Down
4 changes: 2 additions & 2 deletions httpclient/object_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package httpclient

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestObjectClient(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ast.Equal(method, r.Method)
if r.Method != resty.MethodGet {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
ast.NoError(err)
ast.Equal(reqBody, body)
}
Expand Down
3 changes: 1 addition & 2 deletions middleware/keep_request_responce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package middleware

import (
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -86,7 +85,7 @@ func TestReserveRequest(t *testing.T) {
}()

checkBody := func(readCloser io.ReadCloser) {
bodyBytes, err := ioutil.ReadAll(readCloser)
bodyBytes, err := io.ReadAll(readCloser)
assert.NoError(t, err)
if test.method == http.MethodPost {
assert.Equal(t, bodyString, string(bodyBytes))
Expand Down
2 changes: 1 addition & 1 deletion notify/dingtalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewWithDingTalks(configs ...DingTalkConfig) Notifier {
return NewWithStringNotifiers(stringNotifiers...)
}

func newDingTalkNotifier(config DingTalkConfig) StringNotifier { // nolint:gocritic
func newDingTalkNotifier(config DingTalkConfig) StringNotifier { //nolint:gocritic
return &dingTalkNotifier{
client: httpclient.NewObjectClient(dingTalkRobotSendAddr, httpclient.WithQueryParam("access_token", config.AccessToken)),
config: config,
Expand Down
4 changes: 2 additions & 2 deletions notify/dingtalk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package notify
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestDingTalkNotify(t *testing.T) {

testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == resty.MethodPost {
body, err := ioutil.ReadAll(r.Body) //nolint:govet
body, err := io.ReadAll(r.Body) //nolint:govet
ast.NoError(err)
var requestBody dingTalkMessage
err = json.Unmarshal(body, &requestBody)
Expand Down
50 changes: 28 additions & 22 deletions response/standard_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
StandardHandlerBodyJson StandardHandlerBodyType = 0 // nolint:revive
StandardHandlerBodyJson StandardHandlerBodyType = 0 //nolint:revive
StandardHandlerBodyNone StandardHandlerBodyType = 1

StandardHandlerDetailsNone StandardHandlerDetailsType = 0
Expand Down Expand Up @@ -62,30 +62,36 @@ func NewStandardHandler(params StandardHandlerParams) Handler {

// StandardHandlerDataFieldAny is to solve the problem that interface{} cannot be directly returned as the data field.
// For examples:
// var data interface{} = ...
// return &XxxResp {
// Data: data,
// }
//
// var data interface{} = ...
// return &XxxResp {
// Data: data,
// }
//
// The response body is:
// {
// "code": 0,
// "message": "Success",
// "data": {
// "data": ...
// }
// }
//
// {
// "code": 0,
// "message": "Success",
// "data": {
// "data": ...
// }
// }
//
// Once you use StandardHandlerDataFieldAny,
// var data interface{} = ...
// return &XxxResp {
// Data: StandardHandlerDataFieldAny(data),
// }
//
// var data interface{} = ...
// return &XxxResp {
// Data: StandardHandlerDataFieldAny(data),
// }
//
// The response body is:
// {
// "code": 0,
// "message": "Success",
// "data": ...
// }
//
// {
// "code": 0,
// "message": "Success",
// "data": ...
// }
func StandardHandlerDataFieldAny(data interface{}) interface{} {
return &standardHandlerDataFieldAny{data: data}
}
Expand Down Expand Up @@ -220,7 +226,7 @@ func isInterfaceNil(i interface{}) bool {
if i == nil {
return true
}
switch reflect.TypeOf(i).Kind() { // nolint:exhaustive
switch reflect.TypeOf(i).Kind() { //nolint:exhaustive
case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice:
return reflect.ValueOf(i).IsNil()
}
Expand Down
4 changes: 2 additions & 2 deletions validator/regexes.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package validator

const (
const ( //nolint:gocritic
// add your regex string here
)

var (
var ( //nolint:gocritic
// add your regex here with MustCompile
)

0 comments on commit 117be88

Please sign in to comment.