Skip to content

Commit

Permalink
Add Go 1.19 Support (#1355)
Browse files Browse the repository at this point in the history
* Update Go Version to Go1.19.x And add cache

* Fix CI Line endings

* Update test CI Go Version to Go1.19.x And add cache

* Update Gosec Security Scanner CI to securego/gosec@v2.12.0

* Format comment

Go 1.19 adds support for links, lists, and clearer headings in doc comments. As part of this change, gofmt now reformats doc comments to make their rendered meaning clearer. See “Go Doc Comments” for syntax details and descriptions of common mistakes now highlighted by gofmt. As another part of this change, the new package go/doc/comment provides parsing and reformatting of doc comments as well as support for rendering them to HTML, Markdown, and text.

ref: https://tip.golang.org/doc/go1.19
ref: https://tip.golang.org/doc/comment

* Fix doc structure
  • Loading branch information
Aoang committed Aug 14, 2022
1 parent a5f448f commit ea60524
Show file tree
Hide file tree
Showing 20 changed files with 342 additions and 288 deletions.
40 changes: 33 additions & 7 deletions .github/workflows/lint.yml
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
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/golangci-lint@v1.48.0

- 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/golangci-lint@v1.44.2
golangci-lint run
run: golangci-lint run
16 changes: 5 additions & 11 deletions .github/workflows/security.yml
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/gosec@v2.12.0
with:
args: '-exclude=G104,G304,G402 ./...'
19 changes: 17 additions & 2 deletions .github/workflows/test.yml
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
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
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
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
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
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
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
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
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
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

0 comments on commit ea60524

Please sign in to comment.