Skip to content

Commit

Permalink
replace ioutil with io and os (#2327)
Browse files Browse the repository at this point in the history
set the go version to 1.16 in pr.yml and tests.yml, so as to be consistent with the version in go.mod.
  • Loading branch information
ahrtr committed Oct 30, 2021
1 parent ed690ed commit 5d5aee1
Show file tree
Hide file tree
Showing 36 changed files with 84 additions and 95 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Check out code into the Go module directory
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Check out code into the Go module directory
Expand Down
6 changes: 3 additions & 3 deletions api/server/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"go-micro.dev/v4/api/server"
"go-micro.dev/v4/api/server/cors"
"io/ioutil"
"io"
"net/http"
"testing"
)
Expand All @@ -28,7 +28,7 @@ func TestHTTPServer(t *testing.T) {
}
defer rsp.Body.Close()

b, err := ioutil.ReadAll(rsp.Body)
b, err := io.ReadAll(rsp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestCORSHTTPServer(t *testing.T) {
}
defer rsp.Body.Close()

b, err := ioutil.ReadAll(rsp.Body)
b, err := io.ReadAll(rsp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions broker/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
"net/http"
Expand Down Expand Up @@ -300,7 +299,7 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) {

req.ParseForm()

b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
if err != nil {
errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err)
w.WriteHeader(500)
Expand Down Expand Up @@ -558,7 +557,7 @@ func (h *httpBroker) Publish(topic string, msg *Message, opts ...PublishOption)
}

// discard response body
io.Copy(ioutil.Discard, r.Body)
io.Copy(io.Discard, r.Body)
r.Body.Close()
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/protoc-gen-micro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
package main

import (
"io/ioutil"
"io"
"os"

"go-micro.dev/v4/cmd/protoc-gen-micro/generator"
Expand All @@ -63,7 +63,7 @@ func main() {
// report failure.
g := generator.New()

data, err := ioutil.ReadAll(os.Stdin)
data, err := io.ReadAll(os.Stdin)
if err != nil {
g.Error(err, "reading input")
}
Expand Down
3 changes: 1 addition & 2 deletions codec/bytes/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package bytes
import (
"fmt"
"io"
"io/ioutil"

"go-micro.dev/v4/codec"
)
Expand All @@ -24,7 +23,7 @@ func (c *Codec) ReadHeader(m *codec.Message, t codec.MessageType) error {

func (c *Codec) ReadBody(b interface{}) error {
// read bytes
buf, err := ioutil.ReadAll(c.Conn)
buf, err := io.ReadAll(c.Conn)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions codec/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package proto

import (
"io"
"io/ioutil"

"go-micro.dev/v4/codec"
"github.com/golang/protobuf/proto"
Expand All @@ -21,7 +20,7 @@ func (c *Codec) ReadBody(b interface{}) error {
if b == nil {
return nil
}
buf, err := ioutil.ReadAll(c.Conn)
buf, err := io.ReadAll(c.Conn)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions codec/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package text
import (
"fmt"
"io"
"io/ioutil"

"go-micro.dev/v4/codec"
)
Expand All @@ -24,7 +23,7 @@ func (c *Codec) ReadHeader(m *codec.Message, t codec.MessageType) error {

func (c *Codec) ReadBody(b interface{}) error {
// read bytes
buf, err := ioutil.ReadAll(c.Conn)
buf, err := io.ReadAll(c.Conn)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions config/source/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

import (
"flag"
"io/ioutil"
"io"
"os"
"strings"
"time"
Expand Down Expand Up @@ -119,7 +119,7 @@ func NewSource(opts ...source.Option) source.Source {
}

// parse flags
set.SetOutput(ioutil.Discard)
set.SetOutput(io.Discard)
set.Parse(os.Args[1:])

// normalise flags
Expand Down
4 changes: 2 additions & 2 deletions config/source/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package file

import (
"io/ioutil"
"io"
"os"

"go-micro.dev/v4/config/source"
Expand All @@ -23,7 +23,7 @@ func (f *file) Read() (*source.ChangeSet, error) {
return nil, err
}
defer fh.Close()
b, err := ioutil.ReadAll(fh)
b, err := io.ReadAll(fh)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions examples/config/modify/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"

"go-micro.dev/v4/config"
"github.com/asim/go-micro/plugins/config/encoder/toml/v4"
Expand Down Expand Up @@ -51,7 +51,7 @@ func main() {
}

// write the file
if err := ioutil.WriteFile("./example.conf", v, 0644); err != nil {
if err := os.WriteFile("./example.conf", v, 0644); err != nil {
fmt.Println(err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions examples/greeter/cli/sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/golang/protobuf/proto"
Expand All @@ -24,7 +24,7 @@ func main() {
}
defer r.Body.Close()

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
fmt.Println(err)
return
Expand Down
8 changes: 4 additions & 4 deletions plugins/auth/jwt/token/jwt_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package token

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

"go-micro.dev/v4/auth"
)

func TestGenerate(t *testing.T) {
privKey, err := ioutil.ReadFile("test/sample_key")
privKey, err := os.ReadFile("test/sample_key")
if err != nil {
t.Fatalf("Unable to read private key: %v", err)
}
Expand All @@ -25,11 +25,11 @@ func TestGenerate(t *testing.T) {
}

func TestInspect(t *testing.T) {
pubKey, err := ioutil.ReadFile("test/sample_key.pub")
pubKey, err := os.ReadFile("test/sample_key.pub")
if err != nil {
t.Fatalf("Unable to read public key: %v", err)
}
privKey, err := ioutil.ReadFile("test/sample_key")
privKey, err := os.ReadFile("test/sample_key")
if err != nil {
t.Fatalf("Unable to read private key: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions plugins/broker/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
"net/http"
Expand Down Expand Up @@ -304,7 +303,7 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) {

req.ParseForm()

b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
if err != nil {
errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err)
w.WriteHeader(500)
Expand Down Expand Up @@ -562,7 +561,7 @@ func (h *httpBroker) Publish(topic string, msg *broker.Message, opts ...broker.P
}

// discard response body
io.Copy(ioutil.Discard, r.Body)
io.Copy(io.Discard, r.Body)
r.Body.Close()
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/broker/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"

"go-micro.dev/v4/broker"
Expand Down Expand Up @@ -109,7 +108,7 @@ func (s *sidecar) Publish(topic string, msg *broker.Message, opts ...broker.Publ
}

// discard response
io.Copy(ioutil.Discard, rsp.Body)
io.Copy(io.Discard, rsp.Body)
rsp.Body.Close()

return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/client/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -137,7 +137,7 @@ func (h *httpClient) call(ctx context.Context, node *registry.Node, req client.R
defer hrsp.Body.Close()

// parse response
b, err = ioutil.ReadAll(hrsp.Body)
b, err = io.ReadAll(hrsp.Body)
if err != nil {
return errors.InternalServerError("go.micro.client", err.Error())
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/client/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"testing"
Expand Down Expand Up @@ -41,7 +41,7 @@ func TestHTTPClient(t *testing.T) {
http.Error(w, "codec not found", 500)
return
}
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), 500)
return
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestHTTPClientStream(t *testing.T) {
http.Error(w, "codec not found", 500)
return
}
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), 500)
return
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestHTTPClientStream(t *testing.T) {
return
}

b, err = ioutil.ReadAll(r.Body)
b, err = io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), 500)
return
Expand Down
4 changes: 2 additions & 2 deletions plugins/client/http/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (h *httpStream) Recv(msg interface{}) error {
}
defer rsp.Body.Close()

b, err := ioutil.ReadAll(rsp.Body)
b, err := io.ReadAll(rsp.Body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/config/source/pkger/pkger.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pkger

import (
"io/ioutil"
"io"

"github.com/markbates/pkger"
"go-micro.dev/v4/config/source"
Expand All @@ -22,7 +22,7 @@ func (f *file) Read() (*source.ChangeSet, error) {
return nil, err
}
defer fh.Close()
b, err := ioutil.ReadAll(fh)
b, err := io.ReadAll(fh)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 5d5aee1

Please sign in to comment.