From 7d60fc848be8b7969425dfa3277f8a8d28e2b79e Mon Sep 17 00:00:00 2001 From: vicanso Date: Tue, 5 Jul 2022 20:35:32 +0800 Subject: [PATCH] docs: update documents --- docs/http2_http3.md | 2 +- go.mod | 2 +- go.sum | 4 ++-- middleware/cache.go | 10 +++++----- middleware/cache_compressor.go | 6 +++--- middleware/cache_test.go | 2 +- middleware/compress.go | 2 +- middleware/logger.go | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/http2_http3.md b/docs/http2_http3.md index 9d0ee62..921a759 100644 --- a/docs/http2_http3.md +++ b/docs/http2_http3.md @@ -180,7 +180,7 @@ curl -v --http2-prior-knowledge http://127.0.0.1:3000/ ## http3 -http3现在支持的浏览器只有chrome canary以及firefox最新版本,golang的http模块也未支持http3,http3的前景虽然并不确定,但是还是可以先尝尝鲜,需要注意http3还是试验性质,不要在正式环境中大规模使用。下面是使用[quic-go](https://github.com/lucas-clemente/quic-go)使用http3的示例: +http3现在支持的浏览器只有chrome canary以及firefox最新版本,虽然http3的标准方案已确定,但是需要注意http3模块的使用范围并不广泛,建议不要在正式环境中大规模使用。下面是使用[quic-go](https://github.com/lucas-clemente/quic-go)使用http3的示例: ```go package main diff --git a/go.mod b/go.mod index 3e1c2db..edd8b99 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/andybalholm/brotli v1.0.4 - github.com/stretchr/testify v1.7.5 + github.com/stretchr/testify v1.8.0 github.com/tidwall/gjson v1.14.1 github.com/vicanso/hes v0.6.0 github.com/vicanso/intranet-ip v0.1.0 diff --git a/go.sum b/go.sum index 0a32e22..c72edc6 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q= -github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= diff --git a/middleware/cache.go b/middleware/cache.go index c0b48a7..f95472a 100644 --- a/middleware/cache.go +++ b/middleware/cache.go @@ -250,7 +250,7 @@ func (cp *CacheResponse) Bytes() []byte { func (cp *CacheResponse) GetBody(acceptEncoding string, compressor CacheCompressor) (*bytes.Buffer, string, error) { if compressor != nil && cp.Compression == compressor.GetCompression() { encoding := compressor.GetEncoding() - // client acccept the encoding + // client accept the encoding if strings.Contains(acceptEncoding, encoding) { return cp.Body, encoding, nil } @@ -264,7 +264,7 @@ func (cp *CacheResponse) GetBody(acceptEncoding string, compressor CacheCompress return cp.Body, "", nil } -// SetBody sets body to http response, it will be matched acccept-encoding +// SetBody sets body to http response, it will be matched accept-encoding func (cp *CacheResponse) SetBody(c *elton.Context, compressor CacheCompressor) error { // 如果body不为空 if cp.Body != nil && cp.Body.Len() != 0 { @@ -308,7 +308,7 @@ func NewCacheResponse(data []byte) *CacheResponse { hs := HTTPHeaders(data[offset : offset+size]) offset += size - commpression := data[offset] + compression := data[offset] offset += compressionBytesSize body := data[offset:] @@ -318,7 +318,7 @@ func NewCacheResponse(data []byte) *CacheResponse { CreatedAt: createdAt, StatusCode: int(statusCode), Header: hs.Header(), - Compression: CompressionType(commpression), + Compression: CompressionType(compression), Body: bytes.NewBuffer(body), } } @@ -416,7 +416,7 @@ func NewCache(config CacheConfig) elton.Handler { if err != nil { return err } - compressionType := CompressionNon + compressionType := CompressionNone if compressor != nil && compressor.IsValid(c.GetHeader(elton.HeaderContentType), buffer.Len()) { // 符合压缩条件 diff --git a/middleware/cache_compressor.go b/middleware/cache_compressor.go index 50f159e..bfa0698 100644 --- a/middleware/cache_compressor.go +++ b/middleware/cache_compressor.go @@ -32,7 +32,7 @@ type CompressionType uint8 const ( // not compress - CompressionNon CompressionType = iota + CompressionNone CompressionType = iota // gzip compress CompressionGzip // br compress @@ -90,7 +90,7 @@ func (br *CacheBrCompressor) IsValid(contentType string, length int) bool { func (br *CacheBrCompressor) Compress(buffer *bytes.Buffer) (*bytes.Buffer, CompressionType, error) { data, err := BrotliCompress(buffer.Bytes(), br.Level) if err != nil { - return nil, CompressionNon, err + return nil, CompressionNone, err } return data, CompressionBr, nil } @@ -122,7 +122,7 @@ func (g *CacheGzipCompressor) IsValid(contentType string, length int) bool { func (g *CacheGzipCompressor) Compress(buffer *bytes.Buffer) (*bytes.Buffer, CompressionType, error) { data, err := GzipCompress(buffer.Bytes(), g.Level) if err != nil { - return nil, CompressionNon, err + return nil, CompressionNone, err } return data, CompressionGzip, nil } diff --git a/middleware/cache_test.go b/middleware/cache_test.go index 0da2d07..688257e 100644 --- a/middleware/cache_test.go +++ b/middleware/cache_test.go @@ -224,7 +224,7 @@ func TestCacheResponseGetBody(t *testing.T) { { newRespone: func() *CacheResponse { return &CacheResponse{ - Compression: CompressionNon, + Compression: CompressionNone, Body: bytes.NewBuffer(data), } }, diff --git a/middleware/compress.go b/middleware/compress.go index bede5ee..f02d544 100644 --- a/middleware/compress.go +++ b/middleware/compress.go @@ -202,7 +202,7 @@ func NewCompress(config CompressConfig) elton.Handler { newBuf, e := compressor.Compress(body, levels...) // 如果压缩成功,则使用压缩数据 - // 失败则忽略 + // 失败则忽略(不修改原数据,仅触发error) if e != nil { c.Elton().EmitError(c, e) } else { diff --git a/middleware/logger.go b/middleware/logger.go index 85eacfb..5bbe2dc 100644 --- a/middleware/logger.go +++ b/middleware/logger.go @@ -310,7 +310,7 @@ func formatLog(c *elton.Context, tags []*LoggerTag, startedAt time.Time, default return strings.Join(arr, "") } -// NewLogger returns a new logger middleware, it can log the field of querystring, header, cookie and context. +// NewLogger returns a new logger middleware, it can log the field of query string, header, cookie and context. // It will throw a panic if the Format is empty. // It will throw a panic if the OnLog function is nil. func NewLogger(config LoggerConfig) elton.Handler {