Skip to content

Commit 12ed44c

Browse files
committed
review: typo, lint, and linter configuation.
1 parent e847c66 commit 12ed44c

18 files changed

+47
-47
lines changed

.github/workflows/main.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
# https://github.com/marketplace/actions/setup-go-environment
2019
- name: Set up Go ${{ env.GO_VERSION }}
2120
uses: actions/setup-go@v2
2221
with:
2322
go-version: ${{ env.GO_VERSION }}
2423

25-
# https://github.com/marketplace/actions/checkout
2624
- name: Check out code
2725
uses: actions/checkout@v2
2826
with:
2927
fetch-depth: 0
3028

31-
# https://github.com/marketplace/actions/cache
3229
- name: Cache Go modules
3330
uses: actions/cache@v2
3431
with:
@@ -39,17 +36,15 @@ jobs:
3936
4037
- name: Check and get dependencies
4138
run: |
42-
go mod download
4339
go mod tidy
4440
git diff --exit-code go.mod
4541
git diff --exit-code go.sum
4642
47-
# https://golangci-lint.run/usage/install#other-ci
4843
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
4944
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
5045

5146
- name: Launch test
5247
run: go test ./
5348

5449
- name: golangci-lint
55-
run: golangci-lint run
50+
run: golangci-lint run

.golangci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ issues:
8686
- 'ST1000: at least one file in a package should have a package comment'
8787
- 'G204: Subprocess launched with variable'
8888
- 'G304: Potential file inclusion via variable'
89+
- 'ST1020: comment on exported (.*)'
8990
- 'exported: exported (.*) be unexported'
9091
- 'exported: comment on exported (.*)'
91-
- 'ST1020: comment on exported (.*)'
9292

9393
exclude-rules:
94+
- path: http2utils/utils.go
95+
text: 'G103: Use of unsafe calls should be audited'
9496
- path: hpack.go
9597
text: 'SA6002: argument should be pointer-like to avoid allocations'
9698
- path: hpack.go
@@ -99,7 +101,5 @@ issues:
99101
text: 'SA9003: empty branch'
100102
- path: server.go
101103
text: 'appendAssign: append result not assigned to the same slice'
102-
- path: http2utils/utils.go
103-
text: 'G103: Use of unsafe calls should be audited'
104104
- path: server.go
105105
text: 'cyclomatic complexity 34 of func'

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HTTP2
22

3-
http2 is a implementation of HTTP/2 protocol for [fasthttp](https://github.com/valyala/fasthttp).
3+
http2 is an implementation of HTTP/2 protocol for [fasthttp](https://github.com/valyala/fasthttp).
44

55
# Download
66

@@ -10,14 +10,16 @@ go get github.com/dgrr/[email protected]
1010

1111
# Help
1212

13-
If you need any help setting up, contributing or understanding this repo, you can contact me on [gofiber's Discord](https://gofiber.io/discord).
13+
If you need any help to set up, contributing or understanding this repo, you can contact me on [gofiber's Discord](https://gofiber.io/discord).
1414

1515
# How to use the server?
1616

1717
The server can only be used if your server supports TLS.
1818
Then, you can call [ConfigureServer](https://pkg.go.dev/github.com/dgrr/[email protected]/http2#ConfigureServer).
1919

2020
```go
21+
package main
22+
2123
import (
2224
"github.com/valyala/fasthttp"
2325
"github.com/dgrr/http2"

SECURITY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ endeavor to keep you informed of the progress being made towards a fix and full
1919
These updates will be sent at least every five days.
2020
In reality, this is more likely to be every 24-48 hours.
2121

22-
If you have not received a reply to your email within 48 hours or you have not heard from the security
22+
If you have not received a reply to your email within 48 hours, or you have not heard from the security
2323
team for the past five days please contact us by email to [email protected] or by Telegram message
2424
to [our support](https://t.me/highload_support).
2525
Please note that [email protected] list includes all developers, who may be outside our opensource security team.
@@ -56,7 +56,7 @@ If you have any suggestions to improve this policy, please send an email to oss-
5656

5757
### PGP Key for [email protected]
5858

59-
We accept PGP-encrypted email, but the majority of the security team are not regular PGP users
59+
We accept PGP-encrypted email, but the majority of the security team are not regular PGP users,
6060
so it's somewhat inconvenient. Please only use PGP for critical security reports.
6161

6262
```

client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type ClientOpts struct {
1818
PingInterval time.Duration
1919

2020
// OnRTT is assigned to every client after creation, and the handler
21-
// will be called after every RTT measurement (after receiving a PONG mesage).
21+
// will be called after every RTT measurement (after receiving a PONG message).
2222
OnRTT func(time.Duration)
2323
}
2424

conn.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func NewConn(c net.Conn, opts ConnOpts) *Conn {
131131
return nc
132132
}
133133

134-
// Dialer allows to create HTTP/2 connections by specifying an address and tls configuration.
134+
// Dialer allows creating HTTP/2 connections by specifying an address and tls configuration.
135135
type Dialer struct {
136136
// Addr is the server's address in the form: `host:port`.
137137
Addr string
@@ -558,7 +558,7 @@ func (c *Conn) readNext() (fr *FrameHeader, err error) {
558558
switch fr.Type() {
559559
case FrameSettings:
560560
st := fr.Body().(*Settings)
561-
if !st.IsAck() { // if has ack, just ignore
561+
if !st.IsAck() { // if it has ack, just ignore
562562
c.handleSettings(st)
563563
}
564564
case FrameWindowUpdate:

data.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (data *Data) EndStream() bool {
4646
return data.endStream
4747
}
4848

49-
// Data returns the byte slice of the data readed/to be sendStream.
49+
// Data returns the byte slice of the data read/to be sendStream.
5050
func (data *Data) Data() []byte {
5151
return data.b
5252
}

demo/go.sum

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ github.com/andybalholm/brotli v1.0.2 h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXog
22
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/dgrr/http2 v0.0.3 h1:2NijwvdUOP3AAAqViZL+U4iQgRJcjujnVEqLa7Q07J0=
6-
github.com/dgrr/http2 v0.0.3/go.mod h1:8048JZlnCAoD1CzeLKt0Tjjphzn6gCwZjYkCYp57Mb8=
7-
github.com/dgrr/websocket v0.0.7 h1:cC5iErIMYpu+W1tWB1NOfVPKhgAASf+Tl0sAdEHAxkQ=
8-
github.com/dgrr/websocket v0.0.7/go.mod h1:d30hG8q3dQuz6eSwROXzIodSvPTNi52j1VvxrK7RWXc=
5+
github.com/dgrr/http2 v0.1.1 h1:Xkkiv3i+nl75R9bS9+lawAL2IkQzDkHw9VT2KbzwSb8=
6+
github.com/dgrr/http2 v0.1.1/go.mod h1:534gu4ElcxFQDGimb9zgrC2cYTrQG2TdldOEnMSEPB8=
97
github.com/dgrr/websocket v0.0.8 h1:8zQndnzaeo8wlxbbQXO/L9zWA9CNoTfD1dASdiSbJ34=
108
github.com/dgrr/websocket v0.0.8/go.mod h1:d30hG8q3dQuz6eSwROXzIodSvPTNi52j1VvxrK7RWXc=
119
github.com/fasthttp/router v1.4.0 h1:sWMk0q7M6Qj73eLIolh/934mKTNZIWDrEPDhZUF1pAg=

demo/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func newBTCTiles() fasthttp.RequestHandler {
5252
var row [][]byte
5353
for xi := 0; xi < xt; xi++ {
5454
si := im.(subImager).SubImage(image.Rectangle{
55-
Min: image.Point{xi * tileSize, yi * tileSize},
56-
Max: image.Point{(xi + 1) * tileSize, (yi + 1) * tileSize},
55+
Min: image.Point{X: xi * tileSize, Y: yi * tileSize},
56+
Max: image.Point{X: (xi + 1) * tileSize, Y: (yi + 1) * tileSize},
5757
})
5858
buf := new(bytes.Buffer)
5959
if err := jpeg.Encode(buf, si, &jpeg.Options{Quality: 90}); err != nil {

errors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ var (
101101
HTTP11Required: "HTTP/1.1 required",
102102
}
103103

104-
// This error codes must be used with FrameGoAway.
105-
ErrUnknowFrameType = NewError(
104+
// ErrUnknownFrameType This error codes must be used with FrameGoAway.
105+
ErrUnknownFrameType = NewError(
106106
ProtocolError, "unknown frame type")
107107
ErrMissingBytes = NewError(
108108
ProtocolError, "missing payload bytes. Need more")

examples/client/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/dgrr/http2"
7-
"github.com/valyala/fasthttp"
86
"log"
97
"sync"
108
"sync/atomic"
119
"time"
10+
11+
"github.com/dgrr/http2"
12+
"github.com/valyala/fasthttp"
1213
)
1314

1415
func main() {

frameHeader.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import (
1010
)
1111

1212
const (
13-
// FrameHeader default size
13+
// DefaultFrameSize FrameHeader default size
1414
// http://httpwg.org/specs/rfc7540.html#FrameHeader
1515
DefaultFrameSize = 9
1616
// https://httpwg.org/specs/rfc7540.html#SETTINGS_MAX_FRAME_SIZE
1717
defaultMaxLen = 1 << 14
18+
)
1819

19-
// Frame Flag (described along the frame types)
20-
// More flags have been ignored due to redundancy.
20+
// Frame Flag (described along the frame types)
21+
// More flags have been ignored due to redundancy.
22+
const (
2123
FlagAck FrameFlags = 0x1
2224
FlagEndStream FrameFlags = 0x1
2325
FlagEndHeaders FrameFlags = 0x4
@@ -192,7 +194,7 @@ func (f *FrameHeader) readFrom(br *bufio.Reader) (int64, error) {
192194

193195
if f.kind > FrameContinuation {
194196
_, _ = br.Discard(f.length)
195-
return 0, ErrUnknowFrameType
197+
return 0, ErrUnknownFrameType
196198
}
197199
f.fr = AcquireFrame(f.kind)
198200

headerField.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ func (hf *HeaderField) SetValue(value string) {
108108
hf.value = append(hf.value[:0], value...)
109109
}
110110

111-
// SetKeyString sets key to the field.
111+
// SetKeyBytes sets key to the field.
112112
func (hf *HeaderField) SetKeyBytes(key []byte) {
113113
hf.key = append(hf.key[:0], key...)
114114
}
115115

116-
// SetValueString sets value to the field.
116+
// SetValueBytes sets value to the field.
117117
func (hf *HeaderField) SetValueBytes(value []byte) {
118118
hf.value = append(hf.value[:0], value...)
119119
}

hpack.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// HPACK represents header compression methods to
1111
// encode and decode header fields in HTTP/2.
1212
//
13-
// HPACK is equivalent to a HTTP/1 header.
13+
// HPACK is equivalent to an HTTP/1 header.
1414
//
1515
// Use AcquireHPACK to acquire new HPACK structure.
1616
type HPACK struct {
@@ -19,13 +19,13 @@ type HPACK struct {
1919

2020
// DisableDynamicTable disables the usage of the dynamic table for
2121
// the HPACK structure. If this option is true the HPACK won't add any
22-
// field to the dynamic table unless it was sended by the peer.
22+
// field to the dynamic table unless it was sent by the peer.
2323
//
2424
// This field was implemented because in many ways the server could modify
25-
// the fields stablished by the client losing performance calculated by client.
25+
// the fields established by the client losing performance calculated by client.
2626
DisableDynamicTable bool
2727

28-
// the dynamic table is in a inverse order.
28+
// the dynamic table is in an inverse order.
2929
//
3030
// the insertion point should be the beginning. But we are going to do
3131
// the opposite, insert on the end and drop on the beginning.
@@ -162,7 +162,7 @@ func (hp *HPACK) peek(n uint64) *HeaderField {
162162

163163
// find gets the index of existent key in static or dynamic tables.
164164
func (hp *HPACK) search(hf *HeaderField) (n uint64, fullMatch bool) {
165-
// start searching in the dynamic table (probably it contains less fields than the static.
165+
// start searching in the dynamic table (probably it contains fewer fields than the static).
166166
for i, hf2 := range hp.dynamic {
167167
if fullMatch = bytes.Equal(hf.key, hf2.key) && bytes.Equal(hf.value, hf2.value); fullMatch {
168168
n = uint64(maxIndex + len(hp.dynamic) - i - 1)

hpack_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func writeHPACKAndCheck(t *testing.T, hpack *HPACK, r []byte, fields, table []st
445445
}
446446

447447
if i := compare(b, r); i != -1 {
448-
t.Fatalf("failed in %d (%d): %s", i, tableSize, hexComparision(b[i:], r[i:]))
448+
t.Fatalf("failed in %d (%d): %s", i, tableSize, hexComparison(b[i:], r[i:]))
449449
}
450450

451451
n = 0
@@ -720,7 +720,7 @@ func TestHPACKWriteResponseWithHuffman(t *testing.T) { // WithHuffman
720720
ReleaseHPACK(hpack)
721721
}
722722

723-
func hexComparision(b, r []byte) (s string) {
723+
func hexComparison(b, r []byte) (s string) {
724724
s += "\n"
725725
for i := range b {
726726
s += fmt.Sprintf("%x", b[i]) + " "

huffman.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (node *huffmanNode) add(sym byte, code uint32, length uint8) {
106106
}
107107

108108
n := 8 - length
109-
start, end := int(uint8(code<<n)), int(1<<n)
109+
start, end := int(uint8(code<<n)), 1<<n
110110
for i := start; i < start+end; i++ {
111111
node.sub[i] = &huffmanNode{sym: sym, codeLen: length}
112112
}

server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (s *Server) ServeConn(c net.Conn) error {
106106
for err == nil {
107107
fr, err = ReadFrameFromWithSize(sc.br, sc.clientS.frameSize)
108108
if err != nil {
109-
if errors.Is(err, ErrUnknowFrameType) {
109+
if errors.Is(err, ErrUnknownFrameType) {
110110
err = nil
111111
continue
112112
}
@@ -127,7 +127,7 @@ func (s *Server) ServeConn(c net.Conn) error {
127127
switch fr.Type() {
128128
case FrameSettings:
129129
st := fr.Body().(*Settings)
130-
if !st.IsAck() { // if has ack, just ignore
130+
if !st.IsAck() { // if it has ack, just ignore
131131
sc.handleSettings(st)
132132
}
133133
case FrameWindowUpdate:

settings.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ const FrameSettings FrameType = 0x4
44

55
var _ Frame = &Settings{}
66

7+
// default Settings parameters.
78
const (
8-
// default Settings parameters.
99
defaultHeaderTableSize uint32 = 4096
1010
defaultConcurrentStreams uint32 = 100
1111
defaultWindowSize uint32 = 1<<16 - 1
1212
defaultDataFrameSize uint32 = 1 << 14
1313

1414
maxFrameSize = 1<<24 - 1
15+
)
1516

16-
// FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues)
17+
// FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues)
18+
const (
1719
HeaderTableSize uint16 = 0x1
1820
EnablePush uint16 = 0x2
1921
MaxConcurrentStreams uint16 = 0x3
@@ -25,7 +27,7 @@ const (
2527
// Settings is the options to establish between endpoints
2628
// when starting the connection.
2729
//
28-
// This options have been humanize.
30+
// These options have been humanized.
2931
type Settings struct {
3032
ack bool
3133
rawSettings []byte
@@ -84,7 +86,7 @@ func (st *Settings) HeaderTableSize() uint32 {
8486

8587
// SetPush allows to set the PushPromise settings.
8688
//
87-
// If value is true the Push Promise will be enable.
89+
// If value is true the Push Promise will be enabled.
8890
// if not the Push Promise will be disabled.
8991
func (st *Settings) SetPush(value bool) {
9092
st.enablePush = value

0 commit comments

Comments
 (0)