增加golangci-lint配置

This commit is contained in:
GoEdgeLab
2023-08-08 18:14:48 +08:00
parent 1a6753fbc9
commit 6493b85a7c
9 changed files with 89 additions and 27 deletions

74
.golangci.yaml Normal file
View File

@@ -0,0 +1,74 @@
# https://golangci-lint.run/usage/configuration/
linters:
enable-all: true
disable:
- ifshort
- exhaustivestruct
- golint
- nosnakecase
- scopelint
- varcheck
- structcheck
- interfacer
- exhaustivestruct
- maligned
- deadcode
- dogsled
- wrapcheck
- wastedassign
- varnamelen
- testpackage
- thelper
- nilerr
- sqlclosecheck
- paralleltest
- nonamedreturns
- nlreturn
- nakedret
- ireturn
- interfacebloat
- gosmopolitan
- gomnd
- goerr113
- gochecknoglobals
- exhaustruct
- errorlint
- depguard
- exhaustive
- containedctx
- wsl
- cyclop
- dupword
- errchkjson
- contextcheck
- tagalign
- dupl
- forbidigo
- funlen
- goconst
- godox
- gosec
- lll
- nestif
- revive
- unparam
- stylecheck
- gocritic
- gofumpt
- gomoddirectives
- godot
- gofmt
- gocognit
- mirror
- gocyclo
- gochecknoinits
- gci
- maintidx
- prealloc
- goimports
- errname
- musttag
- forcetypeassert
- whitespace
- noctx

View File

@@ -159,7 +159,7 @@ func TestFileStorage_OpenWriter_HTTP(t *testing.T) {
t.Log(writer) t.Log(writer)
resp := &http.Response{ resp := &http.Response{
StatusCode: 200, StatusCode: http.StatusOK,
Header: http.Header{ Header: http.Header{
"Content-Type": []string{"text/html; charset=utf-8"}, "Content-Type": []string{"text/html; charset=utf-8"},
"Last-Modified": []string{"Wed, 06 Jan 2021 10:03:29 GMT"}, "Last-Modified": []string{"Wed, 06 Jan 2021 10:03:29 GMT"},

View File

@@ -53,7 +53,6 @@ func TestAES128CFBMethod_Encrypt2(t *testing.T) {
} }
{ {
a := []byte{1} a := []byte{1}
_, err = method.Decrypt(a) _, err = method.Decrypt(a)
if err != nil { if err != nil {

View File

@@ -9,8 +9,8 @@ func TestOn(t *testing.T) {
type User struct { type User struct {
name string name string
} }
var u = &User{} var u = &User{name: "lily"}
var u2 = &User{} var u2 = &User{name: "lucy"}
events.On("hello", func() { events.On("hello", func() {
t.Log("world") t.Log("world")

View File

@@ -258,6 +258,7 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
} }
var resp *http.Response var resp *http.Response
var respBodyIsClosed bool
var requestErr error var requestErr error
var requestErrCode string var requestErrCode string
if isHTTPOrigin { // 普通HTTP(S)源站 if isHTTPOrigin { // 普通HTTP(S)源站
@@ -296,6 +297,15 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
this.writeCode(http.StatusBadGateway, "The type of origin site has not been supported", "设置的源站类型尚未支持") this.writeCode(http.StatusBadGateway, "The type of origin site has not been supported", "设置的源站类型尚未支持")
return return
} }
if resp != nil && resp.Body != nil {
defer func() {
if !respBodyIsClosed {
_ = resp.Body.Close()
}
}()
}
if requestErr != nil { if requestErr != nil {
// 客户端取消请求,则不提示 // 客户端取消请求,则不提示
httpErr, ok := requestErr.(*url.Error) httpErr, ok := requestErr.(*url.Error)
@@ -324,10 +334,6 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
shouldRetry = true shouldRetry = true
this.uri = oldURI // 恢复备份 this.uri = oldURI // 恢复备份
if resp != nil && resp.Body != nil {
_ = resp.Body.Close()
}
if httpErr.Err != io.EOF { if httpErr.Err != io.EOF {
remotelogs.WarnServer("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Request origin server failed: "+requestErr.Error()) remotelogs.WarnServer("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Request origin server failed: "+requestErr.Error())
} }
@@ -366,9 +372,6 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
this.write50x(requestErr, http.StatusBadGateway, "Failed to read origin site", "源站读取失败", true) this.write50x(requestErr, http.StatusBadGateway, "Failed to read origin site", "源站读取失败", true)
} }
} }
if resp != nil && resp.Body != nil {
_ = resp.Body.Close()
}
return return
} }
@@ -376,9 +379,6 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
if isLowVersionHTTP && resp.ContentLength < 0 { if isLowVersionHTTP && resp.ContentLength < 0 {
this.writer.WriteHeader(http.StatusBadRequest) this.writer.WriteHeader(http.StatusBadRequest)
_, _ = this.writer.WriteString("The content does not support " + this.RawReq.Proto + " request.") _, _ = this.writer.WriteString("The content does not support " + this.RawReq.Proto + " request.")
if resp.Body != nil {
_ = resp.Body.Close()
}
return return
} }
@@ -395,20 +395,12 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
// WAF对出站进行检查 // WAF对出站进行检查
if this.web.FirewallRef != nil && this.web.FirewallRef.IsOn { if this.web.FirewallRef != nil && this.web.FirewallRef.IsOn {
if this.doWAFResponse(resp) { if this.doWAFResponse(resp) {
err := resp.Body.Close()
if err != nil {
remotelogs.WarnServer("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Closing Error (WAF): "+err.Error())
}
return return
} }
} }
// 特殊页面 // 特殊页面
if this.doPage(resp.StatusCode) { if this.doPage(resp.StatusCode) {
err := resp.Body.Close()
if err != nil {
remotelogs.WarnServer("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Closing error (Page): "+err.Error())
}
return return
} }
@@ -499,6 +491,7 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
_, _ = io.CopyBuffer(this.writer, resp.Body, buf) _, _ = io.CopyBuffer(this.writer, resp.Body, buf)
utils.BytePool4k.Put(buf) utils.BytePool4k.Put(buf)
_ = resp.Body.Close() _ = resp.Body.Close()
respBodyIsClosed = true
this.writer.SetOk() this.writer.SetOk()
return return
@@ -550,6 +543,7 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
pool.Put(buf) pool.Put(buf)
var closeErr = resp.Body.Close() var closeErr = resp.Body.Close()
respBodyIsClosed = true
if closeErr != nil { if closeErr != nil {
if !this.canIgnore(closeErr) { if !this.canIgnore(closeErr) {
remotelogs.WarnServer("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Closing error: "+closeErr.Error()) remotelogs.WarnServer("HTTP_REQUEST_REVERSE_PROXY", this.URL()+": Closing error: "+closeErr.Error())

View File

@@ -24,7 +24,6 @@ import (
_ "golang.org/x/image/webp" _ "golang.org/x/image/webp"
"image" "image"
"image/gif" "image/gif"
_ "image/gif"
_ "image/jpeg" _ "image/jpeg"
_ "image/png" _ "image/png"
"io" "io"

View File

@@ -60,7 +60,6 @@ func Println(tag string, description string) {
CreatedAt: time.Now().Unix(), CreatedAt: time.Now().Unix(),
}: }:
default: default:
} }
} }
@@ -78,7 +77,6 @@ func Warn(tag string, description string) {
CreatedAt: time.Now().Unix(), CreatedAt: time.Now().Unix(),
}: }:
default: default:
} }
} }

View File

@@ -79,7 +79,6 @@ func (this *RateLimitWriter) write(p []byte) (n int, err error) {
err = io.EOF err = io.EOF
return return
default: default:
} }
this.written += n this.written += n

View File

@@ -19,7 +19,6 @@ func (this *ResponseGeneralHeaderLengthCheckpoint) IsComposed() bool {
} }
func (this *ResponseGeneralHeaderLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) { func (this *ResponseGeneralHeaderLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
return return
} }