Skip to content

Commit

Permalink
Merge pull request #119 from zchee/v2/remove-ioutil
Browse files Browse the repository at this point in the history
v2: remove deprecated io/ioutil dependency
  • Loading branch information
goccy authored Feb 5, 2024
2 parents 46ddd50 + 4b28339 commit 879d1c4
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 19 deletions.
5 changes: 2 additions & 3 deletions v2/generator/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package generator
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
Expand All @@ -49,7 +48,7 @@ type FileBuffer struct {
}

func (f *FileBuffer) WriteTempFile() error {
file, err := ioutil.TempFile(f.TempDir, fmt.Sprintf("%s_*", f.BaseName))
file, err := os.CreateTemp(f.TempDir, fmt.Sprintf("%s_*", f.BaseName))
if err != nil {
return fmt.Errorf("failed to create temp file for %s: %v", f.BaseName, err)
}
Expand Down Expand Up @@ -109,7 +108,7 @@ func (f *FileBuffer) Postprocess(disableFormat bool) error {

// overwrite the tempfile by gofmt result
// since abs file exists, set perm to 0
if err := ioutil.WriteFile(f.TempFilePath, formatted, 0); err != nil {
if err := os.WriteFile(f.TempFilePath, formatted, 0); err != nil {
return fmt.Errorf("failed to formatted file for %s: %v", f.BaseName, err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions v2/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package generator
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"

Expand Down Expand Up @@ -96,7 +95,7 @@ func (g *Generator) newTemplateSet() *templateSet {
}

func (g *Generator) Generate(schema *models.Schema) error {
tempDir, err := ioutil.TempDir("", "yo_")
tempDir, err := os.MkdirTemp("", "yo_")
if err != nil {
return fmt.Errorf("failed to create temp dir: %v", err)
}
Expand Down
7 changes: 3 additions & 4 deletions v2/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package generator

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -85,19 +84,19 @@ func TestGenerator(t *testing.T) {

t.Logf("generated file path: %v\n", path)

actualContent, err := ioutil.ReadFile(path)
actualContent, err := os.ReadFile(path)
if err != nil {
t.Fatalf("failed to read file: %v", err)
}

expectedFilePath := filepath.Join(tc.expectedFilesDir, info.Name())
expectedContent, err := ioutil.ReadFile(expectedFilePath)
expectedContent, err := os.ReadFile(expectedFilePath)
if os.IsNotExist(err) {
err = os.MkdirAll(filepath.Join(tc.expectedFilesDir), 0766)
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(expectedFilePath, actualContent, 0444)
err = os.WriteFile(expectedFilePath, actualContent, 0444)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package loader

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

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -618,7 +618,7 @@ func setUpTypeLoader(t *testing.T, schema string, opt Option) *TypeLoader {

dir := t.TempDir()

f, err := ioutil.TempFile(dir, "")
f, err := os.CreateTemp(dir, "")
if err != nil {
t.Fatalf("failed to create temp file: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/loader/schema_parser_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ package loader

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

"cloud.google.com/go/spanner/spansql"
)

func NewSchemaParserSource(fpath string) (SchemaSource, error) {
b, err := ioutil.ReadFile(fpath)
b, err := os.ReadFile(fpath)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions v2/loader/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package loader
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -321,7 +321,7 @@ func TestSource(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

f, err := ioutil.TempFile(dir, "")
f, err := os.CreateTemp(dir, "")
if err != nil {
t.Fatalf("failed to create temp file: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package module

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

// ModuleType represents a module type.
Expand Down Expand Up @@ -62,7 +62,7 @@ func (m *module) Type() ModuleType {
}

func (m *module) Load() ([]byte, error) {
b, err := ioutil.ReadFile(m.path)
b, err := os.ReadFile(m.path)
if err != nil {
return nil, fmt.Errorf("failed to read file %s: %w", m.path, err)
}
Expand Down
4 changes: 2 additions & 2 deletions v2/test/testutil/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package testutil
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -238,7 +238,7 @@ func ApplyTestSchema(ctx context.Context, adminClient *dbadmin.DatabaseAdminClie
}
defer file.Close()

b, err := ioutil.ReadAll(file)
b, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("read error: %v", err)
}
Expand Down

0 comments on commit 879d1c4

Please sign in to comment.