Skip to content

Commit

Permalink
Update golangci-lint and gosec
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Aug 26, 2023
1 parent 6aea1e0 commit cdcdddd
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.1
version: v1.54.2
args: --enable=nolintlint,gochecknoinits,bodyclose,gofumpt --verbose
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Run Gosec Security Scanner
uses: securego/gosec@v2.14.0
uses: securego/gosec@v2.17.0
with:
args: '-exclude=G104,G304,G402 ./...'
1 change: 0 additions & 1 deletion b2s_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ import "unsafe"
// Note it may break if string and/or slice header will change
// in the future go versions.
func b2s(b []byte) string {
/* #nosec G103 */
return *(*string)(unsafe.Pointer(&b))
}
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ func (c *Client) mCleaner(m map[string]*HostClient) {
c.mLock.Lock()
for k, v := range m {
v.connsLock.Lock()
/* #nosec G601 */
if v.connsCount == 0 && atomic.LoadInt32(&v.pendingClientRequests) == 0 {
delete(m, k)
}
Expand Down
12 changes: 12 additions & 0 deletions fasthttpadaptor/b2s_new.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build go1.20
// +build go1.20

package fasthttpadaptor

import "unsafe"

// b2s converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
func b2s(b []byte) string {
return unsafe.String(unsafe.SliceData(b), len(b))
}
15 changes: 15 additions & 0 deletions fasthttpadaptor/b2s_old.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !go1.20
// +build !go1.20

package fasthttpadaptor

import "unsafe"

// b2s converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
//
// Note it may break if string and/or slice header will change
// in the future go versions.
func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
6 changes: 0 additions & 6 deletions fasthttpadaptor/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io"
"net/http"
"net/url"
"unsafe"

"github.com/valyala/fasthttp"
)
Expand Down Expand Up @@ -65,8 +64,3 @@ func ConvertRequest(ctx *fasthttp.RequestCtx, r *http.Request, forServer bool) e

return nil
}

func b2s(b []byte) string {
/* #nosec G103 */
return *(*string)(unsafe.Pointer(&b))
}
2 changes: 1 addition & 1 deletion headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const (

// WebSockets
HeaderSecWebSocketAccept = "Sec-WebSocket-Accept"
HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions"
HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions" /* #nosec G101 */
HeaderSecWebSocketKey = "Sec-WebSocket-Key"
HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol"
HeaderSecWebSocketVersion = "Sec-WebSocket-Version"
Expand Down
2 changes: 1 addition & 1 deletion lbclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (cc *LBClient) get() *lbClient {
minT := atomic.LoadUint64(&minC.total)
for _, c := range cs[1:] {
n := c.PendingRequests()
t := atomic.LoadUint64(&c.total)
t := atomic.LoadUint64(&c.total) /* #nosec G601 */
if n < minN || (n == minN && t < minT) {
minC = c
minN = n
Expand Down
2 changes: 0 additions & 2 deletions s2b_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
// Note it may break if string and/or slice header will change
// in the future go versions.
func s2b(s string) (b []byte) {
/* #nosec G103 */
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
/* #nosec G103 */
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Cap = sh.Len
Expand Down

0 comments on commit cdcdddd

Please sign in to comment.