Skip to content

Commit 8d87abe

Browse files
committed
fix: linter issues and examples import
1 parent 4961549 commit 8d87abe

6 files changed

Lines changed: 14 additions & 13 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ jobs:
2727
if: matrix.os == 'ubuntu-latest'
2828
uses: securego/gosec@master
2929
with:
30-
args: -exclude-dir examples ./...
30+
args: -exclude-dir _examples ./...
3131

3232
- name: Run GoVulnCheck
33+
if: matrix.go-version != '1.17.x' && matrix.go-version != '1.18.x'
3334
uses: golang/govulncheck-action@v1
3435
with:
3536
go-version-input: ${{ matrix.go-version }}

_examples/bufferpool/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"sync"
1313
"time"
1414

15-
"github.com/gorilla/websocket"
15+
"github.com/fasthttp/websocket"
1616
)
1717

1818
var addr = flag.String("addr", "localhost:8080", "http service address")

_examples/bufferpool/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
_ "net/http/pprof"
1313

14-
"github.com/gorilla/websocket"
14+
"github.com/fasthttp/websocket"
1515
)
1616

1717
var addr = flag.String("addr", "localhost:8080", "http service address")

mask.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ func maskBytes(key [4]byte, pos int, b []byte) int {
2323
}
2424

2525
// Mask one byte at a time to word boundary.
26-
//#nosec G103 -- (CWE-242) Has been audited
27-
if n := int(uintptr(unsafe.Pointer(&b[0]))) % wordSize; n != 0 {
26+
// #nosec G103 -- (CWE-242) Has been audited
27+
n := int(uintptr(unsafe.Pointer(&b[0]))) % wordSize
28+
if n != 0 {
2829
n = wordSize - n
2930
for i := range b[:n] {
3031
b[i] ^= key[pos&3]
@@ -42,7 +43,7 @@ func maskBytes(key [4]byte, pos int, b []byte) int {
4243
kw := *(*uintptr)(unsafe.Pointer(&k))
4344

4445
// Mask one word at a time.
45-
n := (len(b) / wordSize) * wordSize
46+
n = (len(b) / wordSize) * wordSize
4647
for i := 0; i < n; i += wordSize {
4748
//#nosec G103 -- (CWE-242) Has been audited
4849
*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(i))) ^= kw

server_fasthttp.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ var strPermessageDeflate = []byte("permessage-deflate")
2020

2121
var poolWriteBuffer = sync.Pool{
2222
New: func() interface{} {
23-
var buf []byte
24-
return buf
23+
return new(writePoolData)
2524
},
2625
}
2726

@@ -183,9 +182,9 @@ func (u *FastHTTPUpgrader) Upgrade(ctx *fasthttp.RequestCtx, handler FastHTTPHan
183182

184183
ctx.Hijack(func(netConn net.Conn) {
185184
// var br *bufio.Reader // Always nil
186-
writeBuf := poolWriteBuffer.Get().([]byte)
185+
writeBuf := poolWriteBuffer.Get().(*writePoolData)
187186

188-
c := newConn(netConn, true, u.ReadBufferSize, u.WriteBufferSize, u.WriteBufferPool, nil, writeBuf)
187+
c := newConn(netConn, true, u.ReadBufferSize, u.WriteBufferSize, u.WriteBufferPool, nil, writeBuf.buf)
189188
if subprotocol != nil {
190189
c.subprotocol = strconv.B2S(subprotocol)
191190
}
@@ -196,11 +195,11 @@ func (u *FastHTTPUpgrader) Upgrade(ctx *fasthttp.RequestCtx, handler FastHTTPHan
196195
}
197196

198197
// Clear deadlines set by HTTP server.
199-
netConn.SetDeadline(time.Time{})
198+
_ = netConn.SetDeadline(time.Time{})
200199

201200
handler(c)
202201

203-
writeBuf = writeBuf[0:0]
202+
writeBuf.buf = writeBuf.buf[0:0]
204203
poolWriteBuffer.Put(writeBuf)
205204
})
206205

util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func computeAcceptKey(challengeKey string) string {
2525
}
2626

2727
func computeAcceptKeyBytes(challengeKey []byte) string {
28-
h := sha1.New()
28+
h := sha1.New() //#nosec G401 -- (CWE-326) https://datatracker.ietf.org/doc/html/rfc6455#page-54
2929
h.Write(challengeKey)
3030
h.Write(keyGUID)
3131
return base64.StdEncoding.EncodeToString(h.Sum(nil))

0 commit comments

Comments
 (0)