Skip to content

remove io/ioutil which will be deprecated #168

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 4 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [master, develop]
pull_request:
branches: "*"
schedule:
- cron: '0 2 * * *'

jobs:
build:
Expand All @@ -15,6 +17,8 @@ jobs:
matrix:
go_version:
- 1.18
- 1.19
- 1.20
os:
- ubuntu-latest
steps:
Expand Down
3 changes: 1 addition & 2 deletions config/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package config

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

Expand Down Expand Up @@ -129,7 +128,7 @@ func Load(opts ...Option) error {

for _, cf := range configFiles {
logger.Blue("[Config] Loading config file %s", cf)
contents, err := ioutil.ReadFile(cf)
contents, err := os.ReadFile(cf)
if err != nil {
logger.Red("[Config] Load ioc-golang config file failed. %v\n The load procedure is continue", err)
return nil
Expand Down
4 changes: 2 additions & 2 deletions extension/aop/call/cli/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/spf13/cobra"
"google.golang.org/grpc"
Expand Down Expand Up @@ -56,7 +56,7 @@ var call = &cobra.Command{

paramsJSON := params
if paramsJSON == "" && paramsFile != "" {
data, err := ioutil.ReadFile(paramsFile)
data, err := os.ReadFile(paramsFile)
if err != nil {
logger.Red("iocli call command read param json from %s failed with error = %s", paramsFile, err.Error())
return
Expand Down
4 changes: 2 additions & 2 deletions extension/aop/dynamic_plugin/cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package cli
import (
"context"
"fmt"
"io/ioutil"
"math"
"os"

"github.com/alibaba/ioc-golang/logger"

Expand Down Expand Up @@ -63,7 +63,7 @@ var updateCommand = &cobra.Command{
pluginFilePath := args[2]
pluginName := args[3]

pluginFile, err := ioutil.ReadFile(pluginFilePath)
pluginFile, err := os.ReadFile(pluginFilePath)
if err != nil {
logger.Red("Read plugin file %s failed with error = %s", pluginFilePath, err)
return
Expand Down
4 changes: 2 additions & 2 deletions extension/aop/dynamic_plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package dynamic_plugin
import (
"context"
"fmt"
"io/ioutil"
"os"
"plugin"

"github.com/alibaba/ioc-golang/logger"
Expand All @@ -39,7 +39,7 @@ type dynamicPluginServiceImpl struct {
}

func (d *dynamicPluginServiceImpl) Update(ctx context.Context, req *dynamic_plugin.DynamicPluginUpdateRequest) (*dynamic_plugin.DynamicPluginUpdateResponse, error) {
tempFile, err := ioutil.TempFile("", req.GetPluginName())
tempFile, err := os.CreateTemp("", req.GetPluginName())
defer func() {
_ = tempFile.Close()
}()
Expand Down
3 changes: 1 addition & 2 deletions extension/aop/trace/cli/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io/fs"
"io/ioutil"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -132,7 +131,7 @@ var trace = &cobra.Command{
}

func writeSpans(cacheData bytes.Buffer) {
if err := ioutil.WriteFile(storeToFile, cacheData.Bytes(), fs.ModePerm); err != nil {
if err := os.WriteFile(storeToFile, cacheData.Bytes(), fs.ModePerm); err != nil {
logger.Red("Write cached spans data to %s failed, error is %s", storeToFile, err.Error())
os.Exit(1)
}
Expand Down
6 changes: 3 additions & 3 deletions extension/autowire/rpc/protocol/protocol_impl/iocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -94,7 +94,7 @@ func (i *IOCProtocol) Invoke(invocation dubboProtocol.Invocation) dubboProtocol.
}
}

rspData, _ := ioutil.ReadAll(rsp.Body)
rspData, _ := io.ReadAll(rsp.Body)
replyList := invocation.Reply().(*[]interface{})
finalIsError := false
finalErrorNotNil := false
Expand Down Expand Up @@ -152,7 +152,7 @@ func (i *IOCProtocol) Export(invoker dubboProtocol.Invoker) dubboProtocol.Export
}
}

reqData, err := ioutil.ReadAll(c.Request.Body)
reqData, err := io.ReadAll(c.Request.Body)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error())
return
Expand Down
4 changes: 2 additions & 2 deletions iocli/gen/generator/plugin/common/file_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package common

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

"github.com/alibaba/ioc-golang/extension/autowire/common"
Expand All @@ -28,7 +28,7 @@ ParseExportedMethodInfoFromGoFiles parse all Upper case methods,
func ParseExportedMethodInfoFromGoFiles(structName string, goFilesPath []string) []Method {
exportedMethods := make([]Method, 0)
for _, filePath := range goFilesPath {
data, err := ioutil.ReadFile(filePath)
data, err := os.ReadFile(filePath)
if err != nil {
continue
}
Expand Down
5 changes: 2 additions & 3 deletions iocli/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package init
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -128,7 +127,7 @@ func doWriteFile(path, tmpl string) (err error) {
}
fmt.Println("File -> ", path)

return ioutil.WriteFile(path, data, 0755)
return os.WriteFile(path, data, 0755)
}

func parseTmpl(tmpl string) ([]byte, error) {
Expand All @@ -148,7 +147,7 @@ func determineModPath(projectPath string) (modPath string) {
dir := filepath.Dir(projectPath)
for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
content, _ := ioutil.ReadFile(filepath.Join(dir, "go.mod"))
content, _ := os.ReadFile(filepath.Join(dir, "go.mod"))
mod := find(`module\s+(?P<name>[\S]+)`, string(content), "$name")
name := strings.TrimPrefix(filepath.Dir(projectPath), dir)
name = strings.TrimPrefix(name, string(os.PathSeparator))
Expand Down