Skip to content

Commit

Permalink
refactor: fix lint for go 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Aug 5, 2022
1 parent 7d60fc8 commit cf2a7e9
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
strategy:
matrix:
go:
- '1.19'
- '1.18'
- '1.17'
- '1.16'
Expand Down
3 changes: 1 addition & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"mime"
"mime/multipart"
"net"
Expand Down Expand Up @@ -627,7 +626,7 @@ func (c *Context) ReadFile(key string) ([]byte, *multipart.FileHeader, error) {
return nil, nil, err
}
defer file.Close()
buf, err := ioutil.ReadAll(file)
buf, err := io.ReadAll(file)
if err != nil {
return nil, nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions docs/custom_body_parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -42,7 +42,7 @@ func post() {
if err != nil {
panic(err)
}
result, _ := ioutil.ReadAll(resp.Body)
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}

Expand All @@ -59,7 +59,7 @@ func NewInfluxParser() elton.Handler {
c.GetRequestHeader(elton.HeaderContentType) != ContentTypeIfx {
return c.Next()
}
body, err := ioutil.ReadAll(c.Request.Body)
body, err := io.ReadAll(c.Request.Body)
// 如果读取数据时出错,直接返回
if err != nil {
return
Expand Down Expand Up @@ -109,7 +109,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strconv"
Expand Down Expand Up @@ -141,7 +141,7 @@ func post() {
if err != nil {
panic(err)
}
result, _ := ioutil.ReadAll(resp.Body)
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}

Expand Down
12 changes: 6 additions & 6 deletions docs/http2_http3.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ package main
import (
"bytes"
"crypto/tls"
"io/ioutil"
"io"
"os"

"github.com/vicanso/elton"
)

// 获取证书内容
func getCert() (cert []byte, key []byte, err error) {
// 此处仅简单从文件中读取,在实际使用,是从数据库中读取
cert, err = ioutil.ReadFile("/tmp/me.dev+3.pem")
cert, err = os.ReadFile("/tmp/me.dev+3.pem")
if err != nil {
return
}
key, err = ioutil.ReadFile("/tmp/me.dev+3-key.pem")
key, err = os.ReadFile("/tmp/me.dev+3-key.pem")
if err != nil {
return
}
Expand Down Expand Up @@ -188,7 +189,6 @@ package main
import (
"bytes"
"crypto/tls"
"io/ioutil"
"log"
"net/http"
"time"
Expand All @@ -202,11 +202,11 @@ const listenAddr = ":4000"
// 获取证书内容
func getCert() (cert []byte, key []byte, err error) {
// 此处仅简单从文件中读取,在实际使用,是从数据库中读取
cert, err = ioutil.ReadFile("/tmp/me.dev+3.pem")
cert, err = os.ReadFile("/tmp/me.dev+3.pem")
if err != nil {
return
}
key, err = ioutil.ReadFile("/tmp/me.dev+3-key.pem")
key, err = os.ReadFile("/tmp/me.dev+3-key.pem")
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
require (
github.com/andybalholm/brotli v1.0.4
github.com/stretchr/testify v1.8.0
github.com/tidwall/gjson v1.14.1
github.com/tidwall/gjson v1.14.2
github.com/vicanso/hes v0.6.0
github.com/vicanso/intranet-ip v0.1.0
github.com/vicanso/keygrip v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
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/gjson v1.14.2 h1:6BBkirS0rAHjumnjHF6qgy5d2YAJ1TLIaFE2lzfOLqo=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
Expand Down
3 changes: 1 addition & 2 deletions middleware/body_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -217,7 +216,7 @@ func doGunzip(buf []byte) ([]byte, error) {
return nil, err
}
defer r.Close()
return ioutil.ReadAll(r)
return io.ReadAll(r)
}

type maxBytesReader struct {
Expand Down
3 changes: 1 addition & 2 deletions middleware/body_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"encoding/base64"
"errors"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -246,7 +245,7 @@ func TestMaxBytesReader(t *testing.T) {
}
for _, tt := range tests {
r := MaxBytesReader(tt.reader, tt.max)
result, err := ioutil.ReadAll(r)
result, err := io.ReadAll(r)
assert.Equal(tt.err, err)
assert.Equal(tt.result, result)
}
Expand Down
3 changes: 1 addition & 2 deletions middleware/brotli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ package middleware
import (
"bytes"
"io"
"io/ioutil"

"github.com/andybalholm/brotli"
"github.com/vicanso/elton"
Expand Down Expand Up @@ -92,7 +91,7 @@ func BrotliCompress(buf []byte, level int) (*bytes.Buffer, error) {
// BrotliDecompress decompress data of brotli
func BrotliDecompress(buf []byte) (*bytes.Buffer, error) {
r := brotli.NewReader(bytes.NewBuffer(buf))
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions middleware/compressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"net/http/httptest"
"testing"

Expand Down Expand Up @@ -105,13 +104,13 @@ func TestCompressorPipe(t *testing.T) {
return nil, err
}
defer gzipReader.Close()
return ioutil.ReadAll(gzipReader)
return io.ReadAll(gzipReader)
},
},
{
compressor: new(BrCompressor),
uncompress: func(r io.Reader) ([]byte, error) {
return ioutil.ReadAll(brotli.NewReader(r))
return io.ReadAll(brotli.NewReader(r))
},
},
}
Expand Down
3 changes: 1 addition & 2 deletions middleware/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"

"github.com/vicanso/elton"
)
Expand Down Expand Up @@ -79,7 +78,7 @@ func GzipDecompress(buf []byte) (*bytes.Buffer, error) {
return nil, err
}
defer r.Close()
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions middleware/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package middleware

import (
"io/ioutil"
"net/http/httptest"
"os"
"testing"
Expand Down Expand Up @@ -113,7 +112,7 @@ func TestRenderer(t *testing.T) {

t.Run("render html from file", func(t *testing.T) {
// render file
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
assert.Nil(err)
filename := f.Name()
defer os.Remove(filename)
Expand Down
3 changes: 1 addition & 2 deletions middleware/static_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -111,7 +110,7 @@ func (fs *FS) Stat(file string) os.FileInfo {

// Get get the file's content
func (fs *FS) Get(file string) ([]byte, error) {
return ioutil.ReadFile(file)
return os.ReadFile(file)
}

// NewReader new a reader for file
Expand Down
4 changes: 2 additions & 2 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"bytes"
"context"
"html/template"
"io/ioutil"
"os"
)

type TemplateParser interface {
Expand Down Expand Up @@ -94,7 +94,7 @@ func (ht *HTMLTemplate) Render(ctx context.Context, text string, data interface{
func (ht *HTMLTemplate) RenderFile(ctx context.Context, filename string, data interface{}) (string, error) {
read := ht.readFile
if read == nil {
read = ioutil.ReadFile
read = os.ReadFile
}
buf, err := read(filename)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package elton

import (
"context"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -54,7 +53,7 @@ func TestHTMLTemplate(t *testing.T) {

t.Run("render file", func(t *testing.T) {
// render file
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
assert.Nil(err)
filename := f.Name()
defer os.Remove(filename)
Expand Down

0 comments on commit cf2a7e9

Please sign in to comment.