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

replace ioutil to os (Deprecated from Go 1.16) #95

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
5 changes: 2 additions & 3 deletions gomockhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -117,7 +116,7 @@ func prepareMockgenRunner() mockgen.Runner {
// Plundered from golang/mock/mockgen/parse.go.
// packageNameOfDir get package import path via dir
func packageNameOfDir(srcDir string) (string, error) {
files, err := ioutil.ReadDir(srcDir)
files, err := os.ReadDir(srcDir)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -153,7 +152,7 @@ func parsePackageImport(srcDir string) (string, error) {
if moduleMode != "off" {
currentDir := srcDir
for {
dat, err := ioutil.ReadFile(filepath.Join(currentDir, "go.mod"))
dat, err := os.ReadFile(filepath.Join(currentDir, "go.mod"))
if os.IsNotExist(err) {
if currentDir == filepath.Dir(currentDir) {
// at the root
Expand Down
3 changes: 1 addition & 2 deletions internal/command/generate_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -60,7 +59,7 @@ func (r Runner) GenerateConfig() {
log.Fatalf("failed to run mockgen: %v \nPlease run `%s` and check if mockgen works correctly with your options", err, r.MockgenRunner)
}

file, err := ioutil.ReadFile(r.MockgenRunner.GetDestination())
file, err := os.ReadFile(r.MockgenRunner.GetDestination())
if err != nil {
log.Fatalf("failed read file. filename: %s, err: %w", r.MockgenRunner.GetDestination(), err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/command/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -82,7 +81,7 @@ func (r Runner) Mockgen() {
if err != nil {
return fmt.Errorf("failed to run mockgen: %v \nPlease run `%s` and check if mockgen works correctly with your options", err, runner)
}
file, err := ioutil.ReadFile(runner.GetDestination())
file, err := os.ReadFile(runner.GetDestination())
if err != nil {
return fmt.Errorf("failed read file. filename: %s, err: %w", runner.GetDestination(), err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/mockgen/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mockgen

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -32,7 +31,7 @@ func Checksum(r Runner) (string, error) {
return "", fmt.Errorf("failed to run mockgen: %v \nPlease run `%s` and check if mockgen works correctly with your options", err, r)
}

tmpFile, err := ioutil.ReadFile(tmpFilePath)
tmpFile, err := os.ReadFile(tmpFilePath)
if err != nil {
return "", fmt.Errorf("failed read file. filename: %s, err: %w", tmpFilePath, err)
}
Expand All @@ -55,7 +54,7 @@ func replaceTmpPathWithOriginal(tmpFilePath string, tmpFile []byte) string {
}

func SourceChecksum(r Runner) (string, error) {
file, err := ioutil.ReadFile(r.GetSource())
file, err := os.ReadFile(r.GetSource())
if err != nil {
return "", fmt.Errorf("failed read file. filename: %s, err: %w", r.GetSource(), err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/repository/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/sanposhiho/gomockhandler/internal/model"
Expand All @@ -20,7 +19,7 @@ func (r *Repository) Put(m *model.Config, path string) error {
if err != nil {
return fmt.Errorf("json marshal: %w", err)
}
return ioutil.WriteFile(path, d, 0644)
return os.WriteFile(path, d, 0644)
}

func (r *Repository) Get(path string) (*model.Config, error) {
Expand All @@ -29,7 +28,7 @@ func (r *Repository) Get(path string) (*model.Config, error) {
return nil, err
}

raw, err := ioutil.ReadFile(path)
raw, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("read file: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/util/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

func Tree(dir string) ([]string, error) {
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return []string{}, fmt.Errorf("failed to get dir: %w", err)
}
Expand Down