Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove usage of deprecated io/ioutil #1336

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/protoc-gen-go_cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package main

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

Expand All @@ -25,7 +25,7 @@ import (
)

func main() {
reqBytes, err := ioutil.ReadAll(os.Stdin)
reqBytes, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/protoc-gen-go_gapic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package main

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

Expand All @@ -25,7 +25,7 @@ import (
)

func main() {
reqBytes, err := ioutil.ReadAll(os.Stdin)
reqBytes, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/gengapic/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package gengapic

import (
"fmt"
"io/ioutil"
"os"
"strings"
"time"
Expand Down Expand Up @@ -110,7 +109,7 @@ func (g *generator) init(req *plugin.CodeGeneratorRequest) error {
files = append(files, wellKnownTypeFiles...)

if opts.serviceConfigPath != "" {
y, err := ioutil.ReadFile(opts.serviceConfigPath)
y, err := os.ReadFile(opts.serviceConfigPath)
if err != nil {
return errors.E(nil, "error reading service config: %v", err)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/gengapic/genrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ func (g *generator) pagingRESTCall(servName string, m *descriptor.MethodDescript
p(` return err`)
p(" }")
p("")
p(" buf, err := ioutil.ReadAll(httpRsp.Body)")
p(" buf, err := io.ReadAll(httpRsp.Body)")
p(" if err != nil {")
p(` return err`)
p(" }")
Expand All @@ -865,7 +865,7 @@ func (g *generator) pagingRESTCall(servName string, m *descriptor.MethodDescript
p("}")

g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/iterator"}] = true
g.imports[pbinfo.ImportSpec{Path: "io/ioutil"}] = true
g.imports[pbinfo.ImportSpec{Path: "io"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/protobuf/proto"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/protobuf/encoding/protojson"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/googleapi"}] = true
Expand Down Expand Up @@ -964,7 +964,7 @@ func (g *generator) lroRESTCall(servName string, m *descriptor.MethodDescriptorP
p(" return err")
p(" }")
p("")
p(" buf, err := ioutil.ReadAll(httpRsp.Body)")
p(" buf, err := io.ReadAll(httpRsp.Body)")
p(" if err != nil {")
p(" return err")
p(" }")
Expand All @@ -989,7 +989,7 @@ func (g *generator) lroRESTCall(servName string, m *descriptor.MethodDescriptorP
p("")

g.imports[pbinfo.ImportSpec{Path: "fmt"}] = true
g.imports[pbinfo.ImportSpec{Path: "io/ioutil"}] = true
g.imports[pbinfo.ImportSpec{Path: "io"}] = true
g.imports[pbinfo.ImportSpec{Path: "cloud.google.com/go/longrunning"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/googleapi"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/grpc/metadata"}] = true
Expand Down Expand Up @@ -1172,7 +1172,7 @@ func (g *generator) unaryRESTCall(servName string, m *descriptor.MethodDescripto
p(" return err")
p(" }")
p("")
p(" buf, err := ioutil.ReadAll(httpRsp.Body)")
p(" buf, err := io.ReadAll(httpRsp.Body)")
p(" if err != nil {")
p(" return err")
p(" }")
Expand Down Expand Up @@ -1203,7 +1203,7 @@ func (g *generator) unaryRESTCall(servName string, m *descriptor.MethodDescripto
p(ret)
p("}")

g.imports[pbinfo.ImportSpec{Path: "io/ioutil"}] = true
g.imports[pbinfo.ImportSpec{Path: "io"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/googleapi"}] = true
g.imports[inSpec] = true
g.imports[outSpec] = true
Expand Down
38 changes: 19 additions & 19 deletions internal/gengapic/genrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,9 @@ func TestGenRestMethod(t *testing.T) {
options: &options{diregapic: true},
imports: map[pbinfo.ImportSpec]bool{
{Path: "google.golang.org/protobuf/encoding/protojson"}: true,
{Path: "io/ioutil"}: true,
{Path: "net/url"}: true,
{Path: "fmt"}: true,
{Path: "io"}: true,
{Path: "net/url"}: true,
{Path: "fmt"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Name: "foopb", Path: "google.golang.org/genproto/cloud/foo/v1"}: true,
},
Expand All @@ -769,7 +769,7 @@ func TestGenRestMethod(t *testing.T) {
{Path: "bytes"}: true,
{Path: "fmt"}: true,
{Path: "google.golang.org/protobuf/encoding/protojson"}: true,
{Path: "io/ioutil"}: true,
{Path: "io"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Path: "net/url"}: true,
{Path: "regexp"}: true,
Expand All @@ -786,10 +786,10 @@ func TestGenRestMethod(t *testing.T) {
{Path: "net/url"}: true,
{Path: "google.golang.org/protobuf/encoding/protojson"}: true,
{Path: "fmt"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Path: "google.golang.org/api/iterator"}: true,
{Path: "google.golang.org/protobuf/proto"}: true,
{Path: "io/ioutil"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Path: "google.golang.org/api/iterator"}: true,
{Path: "google.golang.org/protobuf/proto"}: true,
{Path: "io"}: true,
{Name: "foopb", Path: "google.golang.org/genproto/cloud/foo/v1"}: true,
},
},
Expand Down Expand Up @@ -828,13 +828,13 @@ func TestGenRestMethod(t *testing.T) {
{Path: "bytes"}: true,
{Path: "cloud.google.com/go/longrunning"}: true,
{Path: "fmt"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Path: "google.golang.org/grpc/metadata"}: true,
{Path: "google.golang.org/protobuf/encoding/protojson"}: true,
{Path: "io/ioutil"}: true,
{Path: "net/url"}: true,
{Path: "time"}: true,
{Name: "foopb", Path: "google.golang.org/genproto/cloud/foo/v1"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Path: "google.golang.org/grpc/metadata"}: true,
{Path: "google.golang.org/protobuf/encoding/protojson"}: true,
{Path: "io"}: true,
{Path: "net/url"}: true,
{Path: "time"}: true,
{Name: "foopb", Path: "google.golang.org/genproto/cloud/foo/v1"}: true,
{Name: "longrunningpb", Path: "cloud.google.com/go/longrunning/autogen/longrunningpb"}: true,
},
},
Expand All @@ -846,7 +846,7 @@ func TestGenRestMethod(t *testing.T) {
{Path: "bytes"}: true,
{Path: "fmt"}: true,
{Path: "google.golang.org/protobuf/encoding/protojson"}: true,
{Path: "io/ioutil"}: true,
{Path: "io"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Path: "net/url"}: true,
{Path: "regexp"}: true,
Expand All @@ -863,9 +863,9 @@ func TestGenRestMethod(t *testing.T) {
{Path: "bytes"}: true,
{Path: "fmt"}: true,
{Path: "google.golang.org/protobuf/encoding/protojson"}: true,
{Path: "io/ioutil"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Path: "net/url"}: true,
{Path: "io"}: true,
{Path: "google.golang.org/api/googleapi"}: true,
{Path: "net/url"}: true,
{Name: "foopb", Path: "google.golang.org/genproto/cloud/foo/v1"}: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_CustomOp.want
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *fooRESTClient) CustomOp(ctx context.Context, req *foopb.Foo, opts ...ga
return err
}

buf, err := ioutil.ReadAll(httpRsp.Body)
buf, err := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_HttpBodyRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *fooRESTClient) HttpBodyRPC(ctx context.Context, req *foopb.Foo, opts ..
return err
}

buf, err := ioutil.ReadAll(httpRsp.Body)
buf, err := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_LongrunningRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (c *fooRESTClient) LongrunningRPC(ctx context.Context, req *foopb.Foo, opts
return err
}

buf, err := ioutil.ReadAll(httpRsp.Body)
buf, err := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_PagingRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *fooRESTClient) PagingRPC(ctx context.Context, req *foopb.PagedFooReques
return err
}

buf, err := ioutil.ReadAll(httpRsp.Body)
buf, err := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_UnaryRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *fooRESTClient) UnaryRPC(ctx context.Context, req *foopb.Foo, opts ...ga
return err
}

buf, err := ioutil.ReadAll(httpRsp.Body)
buf, err := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_UpdateRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *fooRESTClient) UpdateRPC(ctx context.Context, req *foopb.UpdateRequest,
return err
}

buf, err := ioutil.ReadAll(httpRsp.Body)
buf, err := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/grpc_service_config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package grpc_service_config

import (
"io"
"io/ioutil"
"log"

"github.com/golang/protobuf/ptypes"
Expand All @@ -37,7 +36,7 @@ type Config struct {
// mapped by the names to the specific config values. Use the accessors on the
// resulting Config to retrieve values for a Service or Method.
func New(in io.Reader) (Config, error) {
data, err := ioutil.ReadAll(in)
data, err := io.ReadAll(in)
if err != nil {
return Config{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/txtdiff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package txtdiff

import (
"flag"
"io/ioutil"
"os"
"strings"
"testing"
)
Expand All @@ -30,13 +30,13 @@ func Diff(t *testing.T, name, got, goldenFile string) {
t.Helper()

if *updateGolden {
if err := ioutil.WriteFile(goldenFile, []byte(got), 0644); err != nil {
if err := os.WriteFile(goldenFile, []byte(got), 0644); err != nil {
t.Fatal(err)
}
return
}

wantBytes, err := ioutil.ReadFile(goldenFile)
wantBytes, err := os.ReadFile(goldenFile)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions showcase/compliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package showcase
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -110,7 +109,7 @@ func getComplianceSuite() (*genprotopb.ComplianceSuite, error) {
return nil, err
}

complianceSuiteJSON, err := ioutil.ReadFile(filePath)
complianceSuiteJSON, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("could not open suite file %q", filePath)
}
Expand Down