Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Go 1.19 Support #1355

Merged
merged 6 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,40 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/setup-go@v3
with:
go-version: 1.18.x
go-version: 1.19.x

- name: Get Go cache paths

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aoang curious why you ended up doing this? In wazero, we're noticing the cache doesn't seem to work for golangci-lint and wondering if there's some difference between this and hard-coding (considering it is only run with ubuntu). Any thoughts appreciated!

https://github.com/tetratelabs/wazero/blob/main/.github/workflows/commit.yaml#L46-L52

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id: go-env
run: |
echo "::set-output name=cache::$(go env GOCACHE)"
echo "::set-output name=modcache::$(go env GOMODCACHE)"
- name: Set up Go cache
uses: actions/cache@v3
with:
key: golangci-lint-${{ runner.os }}-go-${{ hashFiles('go.mod') }}
restore-keys: golangci-lint-${{ runner.os }}-go-
path: |
${{ steps.go-env.outputs.cache }}
${{ steps.go-env.outputs.modcache }}

- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/[email protected]

- name: Get golangci-lint cache path
id: golangci-lint-cache-status
run: |
echo "::set-output name=dir::$(golangci-lint cache status | head -1 | sed 's/^Dir: //')"

- name: Set up golangci-lint cache
uses: actions/cache@v3
with:
key: golangci-lint-${{ runner.os }}-golangci-lint-${{ hashFiles('go.mod') }}
restore-keys: golangci-lint-${{ runner.os }}-golangci-lint-
path: ${{ steps.golangci-lint-cache-status.outputs.dir }}

- run: go version
- run: diff -u <(echo -n) <(gofmt -d .)
- name: Run golangci-lint
run: | # https://github.com/golangci/golangci-lint/pull/2438
export PATH=$PATH:$(go env GOPATH)/bin
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run

run: golangci-lint run
16 changes: 5 additions & 11 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ jobs:
test:
strategy:
matrix:
go-version: [1.18.x]
go-version: [1.19.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
env:
GO111MODULE: on
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: Run Gosec Security Scanner
run: | # https://github.com/securego/gosec/issues/469#issuecomment-1070608395
export PATH=$PATH:$(go env GOPATH)/bin
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec -exclude=G104,G304,G402 ./...
uses: securego/[email protected]
with:
args: '-exclude=G104,G304,G402 ./...'
19 changes: 17 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ jobs:
test:
strategy:
matrix:
go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x]
go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Get Go cache paths
id: go-env
run: |
echo "::set-output name=cache::$(go env GOCACHE)"
echo "::set-output name=modcache::$(go env GOMODCACHE)"
- name: Set up Go cache
uses: actions/cache@v3
with:
key: golangci-lint-${{ runner.os }}-go-${{ hashFiles('go.mod') }}
restore-keys: golangci-lint-${{ runner.os }}-go-
path: |
${{ steps.go-env.outputs.cache }}
${{ steps.go-env.outputs.modcache }}

- run: go version
- run: go test ./...
- run: go test -race ./...
16 changes: 8 additions & 8 deletions brotli.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ var (
//
// Supported compression levels are:
//
// * CompressBrotliNoCompression
// * CompressBrotliBestSpeed
// * CompressBrotliBestCompression
// * CompressBrotliDefaultCompression
// - CompressBrotliNoCompression
// - CompressBrotliBestSpeed
// - CompressBrotliBestCompression
// - CompressBrotliDefaultCompression
func AppendBrotliBytesLevel(dst, src []byte, level int) []byte {
w := &byteSliceWriter{dst}
WriteBrotliLevel(w, src, level) //nolint:errcheck
Expand All @@ -107,10 +107,10 @@ func AppendBrotliBytesLevel(dst, src []byte, level int) []byte {
//
// Supported compression levels are:
//
// * CompressBrotliNoCompression
// * CompressBrotliBestSpeed
// * CompressBrotliBestCompression
// * CompressBrotliDefaultCompression
// - CompressBrotliNoCompression
// - CompressBrotliBestSpeed
// - CompressBrotliBestCompression
// - CompressBrotliDefaultCompression
func WriteBrotliLevel(w io.Writer, p []byte, level int) (int, error) {
switch w.(type) {
case *byteSliceWriter,
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ func (e *timeoutError) Error() string {
// Only implement the Timeout() function of the net.Error interface.
// This allows for checks like:
//
// if x, ok := err.(interface{ Timeout() bool }); ok && x.Timeout() {
// if x, ok := err.(interface{ Timeout() bool }); ok && x.Timeout() {
func (e *timeoutError) Timeout() bool {
return true
}
Expand Down
40 changes: 20 additions & 20 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ var (
//
// Supported compression levels are:
//
// * CompressNoCompression
// * CompressBestSpeed
// * CompressBestCompression
// * CompressDefaultCompression
// * CompressHuffmanOnly
// - CompressNoCompression
// - CompressBestSpeed
// - CompressBestCompression
// - CompressDefaultCompression
// - CompressHuffmanOnly
func AppendGzipBytesLevel(dst, src []byte, level int) []byte {
w := &byteSliceWriter{dst}
WriteGzipLevel(w, src, level) //nolint:errcheck
Expand All @@ -143,11 +143,11 @@ func AppendGzipBytesLevel(dst, src []byte, level int) []byte {
//
// Supported compression levels are:
//
// * CompressNoCompression
// * CompressBestSpeed
// * CompressBestCompression
// * CompressDefaultCompression
// * CompressHuffmanOnly
// - CompressNoCompression
// - CompressBestSpeed
// - CompressBestCompression
// - CompressDefaultCompression
// - CompressHuffmanOnly
func WriteGzipLevel(w io.Writer, p []byte, level int) (int, error) {
switch w.(type) {
case *byteSliceWriter,
Expand Down Expand Up @@ -223,11 +223,11 @@ func AppendGunzipBytes(dst, src []byte) ([]byte, error) {
//
// Supported compression levels are:
//
// * CompressNoCompression
// * CompressBestSpeed
// * CompressBestCompression
// * CompressDefaultCompression
// * CompressHuffmanOnly
// - CompressNoCompression
// - CompressBestSpeed
// - CompressBestCompression
// - CompressDefaultCompression
// - CompressHuffmanOnly
func AppendDeflateBytesLevel(dst, src []byte, level int) []byte {
w := &byteSliceWriter{dst}
WriteDeflateLevel(w, src, level) //nolint:errcheck
Expand All @@ -239,11 +239,11 @@ func AppendDeflateBytesLevel(dst, src []byte, level int) []byte {
//
// Supported compression levels are:
//
// * CompressNoCompression
// * CompressBestSpeed
// * CompressBestCompression
// * CompressDefaultCompression
// * CompressHuffmanOnly
// - CompressNoCompression
// - CompressBestSpeed
// - CompressBestCompression
// - CompressDefaultCompression
// - CompressHuffmanOnly
func WriteDeflateLevel(w io.Writer, p []byte, level int) (int, error) {
switch w.(type) {
case *byteSliceWriter,
Expand Down
78 changes: 48 additions & 30 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,53 @@ Package fasthttp provides fast HTTP server and client API.

Fasthttp provides the following features:

* Optimized for speed. Easily handles more than 100K qps and more than 1M
concurrent keep-alive connections on modern hardware.
* Optimized for low memory usage.
* Easy 'Connection: Upgrade' support via RequestCtx.Hijack.
* Server provides the following anti-DoS limits:

* The number of concurrent connections.
* The number of concurrent connections per client IP.
* The number of requests per connection.
* Request read timeout.
* Response write timeout.
* Maximum request header size.
* Maximum request body size.
* Maximum request execution time.
* Maximum keep-alive connection lifetime.
* Early filtering out non-GET requests.

* A lot of additional useful info is exposed to request handler:

* Server and client address.
* Per-request logger.
* Unique request id.
* Request start time.
* Connection start time.
* Request sequence number for the current connection.

* Client supports automatic retry on idempotent requests' failure.
* Fasthttp API is designed with the ability to extend existing client
and server implementations or to write custom client and server
implementations from scratch.
1. Optimized for speed. Easily handles more than 100K qps and more than 1M
concurrent keep-alive connections on modern hardware.

2. Optimized for low memory usage.

3. Easy 'Connection: Upgrade' support via RequestCtx.Hijack.

4. Server provides the following anti-DoS limits:

- The number of concurrent connections.

- The number of concurrent connections per client IP.

- The number of requests per connection.

- Request read timeout.

- Response write timeout.

- Maximum request header size.

- Maximum request body size.

- Maximum request execution time.

- Maximum keep-alive connection lifetime.

- Early filtering out non-GET requests.

5. A lot of additional useful info is exposed to request handler:

- Server and client address.

- Per-request logger.

- Unique request id.

- Request start time.

- Connection start time.

- Request sequence number for the current connection.

6. Client supports automatic retry on idempotent requests' failure.

7. Fasthttp API is designed with the ability to extend existing client
and server implementations or to write custom client and server
implementations from scratch.
*/
package fasthttp
20 changes: 10 additions & 10 deletions fasthttpadaptor/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
// it has the following drawbacks comparing to using manually written fasthttp
// request handler:
//
// * A lot of useful functionality provided by fasthttp is missing
// from net/http handler.
// * net/http -> fasthttp handler conversion has some overhead,
// so the returned handler will be always slower than manually written
// fasthttp handler.
// - A lot of useful functionality provided by fasthttp is missing
// from net/http handler.
// - net/http -> fasthttp handler conversion has some overhead,
// so the returned handler will be always slower than manually written
// fasthttp handler.
//
// So it is advisable using this function only for quick net/http -> fasthttp
// switching. Then manually convert net/http handlers to fasthttp handlers
Expand All @@ -35,11 +35,11 @@ func NewFastHTTPHandlerFunc(h http.HandlerFunc) fasthttp.RequestHandler {
// it has the following drawbacks comparing to using manually written fasthttp
// request handler:
//
// * A lot of useful functionality provided by fasthttp is missing
// from net/http handler.
// * net/http -> fasthttp handler conversion has some overhead,
// so the returned handler will be always slower than manually written
// fasthttp handler.
// - A lot of useful functionality provided by fasthttp is missing
// from net/http handler.
// - net/http -> fasthttp handler conversion has some overhead,
// so the returned handler will be always slower than manually written
// fasthttp handler.
//
// So it is advisable using this function only for quick net/http -> fasthttp
// switching. Then manually convert net/http handlers to fasthttp handlers
Expand Down
2 changes: 2 additions & 0 deletions fasthttpproxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// the provided HTTP proxy.
//
// Example usage:
//
// c := &fasthttp.Client{
// Dial: fasthttpproxy.FasthttpHTTPDialer("username:password@localhost:9050"),
// }
Expand All @@ -26,6 +27,7 @@ func FasthttpHTTPDialer(proxy string) fasthttp.DialFunc {
// the provided HTTP proxy using the given timeout.
//
// Example usage:
//
// c := &fasthttp.Client{
// Dial: fasthttpproxy.FasthttpHTTPDialerTimeout("username:password@localhost:9050", time.Second * 2),
// }
Expand Down
2 changes: 2 additions & 0 deletions fasthttpproxy/proxy_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
// the the env(HTTP_PROXY, HTTPS_PROXY and NO_PROXY) configured HTTP proxy.
//
// Example usage:
//
// c := &fasthttp.Client{
// Dial: FasthttpProxyHTTPDialer(),
// }
Expand All @@ -35,6 +36,7 @@ func FasthttpProxyHTTPDialer() fasthttp.DialFunc {
// the env(HTTP_PROXY, HTTPS_PROXY and NO_PROXY) configured HTTP proxy using the given timeout.
//
// Example usage:
//
// c := &fasthttp.Client{
// Dial: FasthttpProxyHTTPDialerTimeout(time.Second * 2),
// }
Expand Down
1 change: 1 addition & 0 deletions fasthttpproxy/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
// the provided SOCKS5 proxy.
//
// Example usage:
//
// c := &fasthttp.Client{
// Dial: fasthttpproxy.FasthttpSocksDialer("socks5://localhost:9050"),
// }
Expand Down
8 changes: 4 additions & 4 deletions fasthttputil/pipeconns.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func NewPipeConns() *PipeConns {
// PipeConns has the following additional features comparing to connections
// returned from net.Pipe():
//
// * It is faster.
// * It buffers Write calls, so there is no need to have concurrent goroutine
// - It is faster.
// - It buffers Write calls, so there is no need to have concurrent goroutine
// calling Read in order to unblock each Write call.
// * It supports read and write deadlines.
// - It supports read and write deadlines.
//
// PipeConns is NOT safe for concurrent use by multiple goroutines!
type PipeConns struct {
Expand Down Expand Up @@ -209,7 +209,7 @@ func (e *timeoutError) Error() string {
// Only implement the Timeout() function of the net.Error interface.
// This allows for checks like:
//
// if x, ok := err.(interface{ Timeout() bool }); ok && x.Timeout() {
// if x, ok := err.(interface{ Timeout() bool }); ok && x.Timeout() {
func (e *timeoutError) Timeout() bool {
return true
}
Expand Down
Loading