Skip to content

Commit 20a5f84

Browse files
authored
add staticheck into ci (#111)
1 parent 578c8e2 commit 20a5f84

21 files changed

+60
-51
lines changed

.github/workflows/ci-test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ jobs:
1919
go-version: '1.10.x'
2020
- name: Format
2121
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
22+
working-directory: src/github.com/qiniu/go-sdk
2223
- name: Run unit cases
2324
run: |
25+
set -e
2426
GOPATH=$GITHUB_WORKSPACE go get github.com/qiniu/x
2527
GOPATH=$GITHUB_WORKSPACE go get golang.org/x/sync/singleflight
2628
GOPATH=$GITHUB_WORKSPACE go get github.com/qiniu/dyn
@@ -69,8 +71,16 @@ jobs:
6971
go-version: ${{ matrix.go_version }}
7072
- name: Format
7173
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
74+
- name: Golint
75+
run: |
76+
if [ "${{ matrix.go_version }}" = "1.20.x" ]; then
77+
set -e
78+
go install honnef.co/go/tools/cmd/staticcheck@latest
79+
make staticcheck
80+
fi
7281
- name: Run unit cases
7382
run: |
83+
set -e
7484
make unittest
7585
env:
7686
GO111MODULE: 'on'

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ test:
33

44
unittest:
55
go test -tags=unit -failfast -v -coverprofile=coverage.txt `go list ./... | egrep -v 'examples|sms'`
6+
7+
staticcheck:
8+
staticcheck -go 1.10 `go list ./... | egrep -v 'examples|sms'`

client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func parseError(e *ErrorInfo, r io.Reader) {
245245
e.Err = string(body)
246246
}
247247

248-
func ResponseError(resp *http.Response) (err error) {
248+
func ResponseError(resp *http.Response) error {
249249

250250
e := &ErrorInfo{
251251
Reqid: resp.Header.Get("X-Reqid"),
@@ -257,9 +257,9 @@ func ResponseError(resp *http.Response) (err error) {
257257
if ok && strings.HasPrefix(ct[0], "application/json") {
258258
parseError(e, resp.Body)
259259
} else {
260-
bs, rErr := ioutil.ReadAll(resp.Body)
261-
if rErr != nil {
262-
err = rErr
260+
bs, err := ioutil.ReadAll(resp.Body)
261+
if err != nil {
262+
return err
263263
}
264264
e.Err = strings.TrimRight(string(bs), "\n")
265265
}

doc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package api
2+
13
/*
24
包 github.com/qiniu/go-sdk 是七牛 Go 语言 SDK v7.x 版本。
35
@@ -7,4 +9,3 @@ Go SDK 中主要包含几个包:
79
810
auth 包提供鉴权相关方法,conf 包提供配置相关方法,cdn包提供CDN相关的功能,storage包提供存储相关的功能。
911
*/
10-
package api

err.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package api
22

3-
// QINIU SDK error type
4-
3+
// QError QINIU SDK error type
54
// 可以根据Code判断是何种类型错误
65
type QError struct {
76
Code string

internal/clientv2/interceptor_debug.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package clientv2
33
import (
44
"crypto/tls"
55
"fmt"
6-
clientV1 "github.com/qiniu/go-sdk/v7/client"
7-
"github.com/qiniu/go-sdk/v7/internal/log"
86
"net/http"
97
"net/http/httptrace"
108
"net/http/httputil"
9+
10+
clientV1 "github.com/qiniu/go-sdk/v7/client"
11+
"github.com/qiniu/go-sdk/v7/internal/log"
1112
)
1213

1314
type DebugLevel int
@@ -147,10 +148,10 @@ func (interceptor *debugInterceptor) printRequestTrace(label string, req *http.R
147148
log.Debug(label + fmt.Sprintf("PutIdleConn, err:%v \n", err))
148149
},
149150
GotFirstResponseByte: func() {
150-
log.Debug(label + fmt.Sprint("GotFirstResponseByte \n"))
151+
log.Debug(label + "GotFirstResponseByte \n")
151152
},
152153
Got100Continue: func() {
153-
log.Debug(label + fmt.Sprint("Got100Continue \n"))
154+
log.Debug(label + "Got100Continue \n")
154155
},
155156
DNSStart: func(info httptrace.DNSStartInfo) {
156157
log.Debug(label + fmt.Sprintf("DNSStart, host:%s \n", info.Host))
@@ -165,7 +166,7 @@ func (interceptor *debugInterceptor) printRequestTrace(label string, req *http.R
165166
log.Debug(label + fmt.Sprintf("ConnectDone, network:%s ip:%s err:%v \n", network, addr, err))
166167
},
167168
TLSHandshakeStart: func() {
168-
log.Debug(label + fmt.Sprint("TLSHandshakeStart \n"))
169+
log.Debug(label + "TLSHandshakeStart \n")
169170
},
170171
TLSHandshakeDone: func(state tls.ConnectionState, err error) {
171172
log.Debug(label + fmt.Sprintf("TLSHandshakeDone, state:%+v err:%s \n", state, err))
@@ -175,10 +176,10 @@ func (interceptor *debugInterceptor) printRequestTrace(label string, req *http.R
175176
// log.Debug(label + fmt.Sprintf("WroteHeaderField, key:%s value:%s \n", key, value))
176177
//},
177178
WroteHeaders: func() {
178-
log.Debug(label + fmt.Sprint("WroteHeaders \n"))
179+
log.Debug(label + "WroteHeaders \n")
179180
},
180181
Wait100Continue: func() {
181-
log.Debug(label + fmt.Sprint("Wait100Continue \n"))
182+
log.Debug(label + "Wait100Continue \n")
182183
},
183184
WroteRequest: func(info httptrace.WroteRequestInfo) {
184185
log.Debug(label + fmt.Sprintf("WroteRequest, err:%v \n", info.Err))

linking/device.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ type Device struct {
2626
// 0 不录制
2727
// -1 永久
2828
// -2 继承app配置
29-
SegmentExpireDays int `json:"segmentExpireDays,has,omitempty"`
29+
SegmentExpireDays int `json:"segmentExpireDays,omitempty"`
3030

3131
// -1 继承app配置
3232
// 0 遵循设备端配置
3333
// 1 强制持续上传
3434
// 2 强制关闭上传
35-
UploadMode int `json:"uploadMode,has,omitempty"`
35+
UploadMode int `json:"uploadMode,omitempty"`
3636

3737
State int `json:"state,omitempty"`
3838

rtc/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func callReq(httpClient *http.Client, req *http.Request, mac *auth.Credentials,
113113
info.Code = resp.StatusCode
114114
reqid := getReqid(&resp.Header)
115115
rebuildErr := func(msg string) error {
116-
return fmt.Errorf("Code: %v, Reqid: %v, %v", info.Code, reqid, msg)
116+
return fmt.Errorf("code: %v, reqid: %v, %v", info.Code, reqid, msg)
117117
}
118118

119119
if resp.ContentLength > 2*1024*1024 {

storage/bucket.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ func (m *BucketManager) Batch(operations []string) ([]BatchOpRet, error) {
599599
return nil, errors.New("can't get one bucket from operations")
600600
}
601601

602-
return m.BatchWithContext(nil, bucket, operations)
602+
return m.BatchWithContext(context.Background(), bucket, operations)
603603
}
604604

605605
// BatchWithContext 接口提供了资源管理的批量操作,支持 stat,copy,move,delete,chgm,chtype,deleteAfterDays几个接口
@@ -1069,7 +1069,7 @@ func MakePublicURLv2WithQuery(domain, key string, query url.Values) string {
10691069
}
10701070

10711071
// MakePublicURLv2WithQueryString 用来生成公开空间资源下载链接,并且该方法确保 key 将会被 escape,并在 URL 后直接追加查询参数
1072-
func makePublicURLv2WithQueryString(domain, key, query string) string {
1072+
func MakePublicURLv2WithQueryString(domain, key, query string) string {
10731073
return makePublicURLv2WithRawQuery(domain, key, urlEncodeQuery(query))
10741074
}
10751075

storage/bucket_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ func TestMakeURL(t *testing.T) {
10071007
t.Fatalf("TestMakeURL: %q\n", s)
10081008
}
10091009

1010-
s = makePublicURLv2WithQueryString("http://abc.com:123/", "123/def?@#|", "123/def?@#|")
1010+
s = MakePublicURLv2WithQueryString("http://abc.com:123/", "123/def?@#|", "123/def?@#|")
10111011
if s != "http://abc.com:123/123/def%3F@%23%7C?123/def%3F%40%23|" {
10121012
t.Fatalf("TestMakeURL: %q\n", s)
10131013
}

0 commit comments

Comments
 (0)