style(batch-submitter,bss-core,proxyd): Fix lint Go (#3328)

* style(batch-submitter): fix lint

* style(bss-core): fix lint

* chore(proxyd): use io and os instead of deprecated ioutil methods, fixes lint
This commit is contained in:
protolambda 2022-08-27 03:39:30 +02:00 committed by GitHub
parent c76107cdb0
commit 9a4626856a
6 changed files with 11 additions and 14 deletions

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"math/rand" "math/rand"
"net/http" "net/http"
@ -408,7 +407,7 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
} }
defer httpRes.Body.Close() defer httpRes.Body.Close()
resB, err := ioutil.ReadAll(io.LimitReader(httpRes.Body, b.maxResponseSize)) resB, err := io.ReadAll(io.LimitReader(httpRes.Body, b.maxResponseSize))
if err != nil { if err != nil {
return nil, wrapErr(err, "error reading response body") return nil, wrapErr(err, "error reading response body")
} }

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -122,7 +122,7 @@ func (h *BatchRPCResponseRouter) ServeHTTP(w http.ResponseWriter, r *http.Reques
h.mtx.Lock() h.mtx.Lock()
defer h.mtx.Unlock() defer h.mtx.Unlock()
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -241,12 +241,12 @@ func (m *MockBackend) Requests() []*RecordedRequest {
func (m *MockBackend) wrappedHandler(w http.ResponseWriter, r *http.Request) { func (m *MockBackend) wrappedHandler(w http.ResponseWriter, r *http.Request) {
m.mtx.Lock() m.mtx.Lock()
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
panic(err) panic(err)
} }
clone := r.Clone(context.Background()) clone := r.Clone(context.Background())
clone.Body = ioutil.NopCloser(bytes.NewReader(body)) clone.Body = io.NopCloser(bytes.NewReader(body))
m.requests = append(m.requests, &RecordedRequest{ m.requests = append(m.requests, &RecordedRequest{
Method: r.Method, Method: r.Method,
Headers: r.Header.Clone(), Headers: r.Header.Clone(),

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"testing" "testing"
@ -67,7 +67,7 @@ func (p *ProxydHTTPClient) SendRequest(body []byte) ([]byte, int, error) {
} }
defer res.Body.Close() defer res.Body.Close()
code := res.StatusCode code := res.StatusCode
resBody, err := ioutil.ReadAll(res.Body) resBody, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -3,7 +3,6 @@ package proxyd
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"strings" "strings"
) )
@ -103,7 +102,7 @@ func ParseBatchRPCReq(body []byte) ([]json.RawMessage, error) {
} }
func ParseRPCRes(r io.Reader) (*RPCRes, error) { func ParseRPCRes(r io.Reader) (*RPCRes, error) {
body, err := ioutil.ReadAll(r) body, err := io.ReadAll(r)
if err != nil { if err != nil {
return nil, wrapErr(err, "error reading RPC response") return nil, wrapErr(err, "error reading RPC response")
} }

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"net/http" "net/http"
"strconv" "strconv"
@ -236,7 +235,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
"user_agent", userAgent, "user_agent", userAgent,
) )
body, err := ioutil.ReadAll(io.LimitReader(r.Body, s.maxBodySize)) body, err := io.ReadAll(io.LimitReader(r.Body, s.maxBodySize))
if err != nil { if err != nil {
log.Error("error reading request body", "err", err) log.Error("error reading request body", "err", err)
writeRPCError(ctx, w, nil, ErrInternal) writeRPCError(ctx, w, nil, ErrInternal)

@ -4,11 +4,11 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors" "errors"
"io/ioutil" "os"
) )
func CreateTLSClient(ca string) (*tls.Config, error) { func CreateTLSClient(ca string) (*tls.Config, error) {
pem, err := ioutil.ReadFile(ca) pem, err := os.ReadFile(ca)
if err != nil { if err != nil {
return nil, wrapErr(err, "error reading CA") return nil, wrapErr(err, "error reading CA")
} }