Skip to content

Replace deprecated ioutil pkg with os & io #755

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

Merged
merged 1 commit into from
Jul 27, 2022
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
6 changes: 3 additions & 3 deletions database/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package cassandra
import (
"errors"
"fmt"
"go.uber.org/atomic"
"io"
"io/ioutil"
nurl "net/url"
"strconv"
"strings"
"time"

"go.uber.org/atomic"

"github.com/gocql/gocql"
"github.com/golang-migrate/migrate/v4/database"
"github.com/golang-migrate/migrate/v4/database/multistmt"
Expand Down Expand Up @@ -231,7 +231,7 @@ func (c *Cassandra) Run(migration io.Reader) error {
return err
}

migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions database/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"database/sql"
"fmt"
"io"
"io/ioutil"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -153,7 +152,7 @@ func (ch *ClickHouse) Run(r io.Reader) error {
return err
}

migration, err := ioutil.ReadAll(r)
migration, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
14 changes: 4 additions & 10 deletions database/cockroachdb/cockroachdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ import (
"context"
"database/sql"
"fmt"
"go.uber.org/atomic"
"io"
"io/ioutil"
nurl "net/url"
"regexp"
"strconv"
)

import (
"github.com/cockroachdb/cockroach-go/v2/crdb"
"github.com/hashicorp/go-multierror"
"github.com/lib/pq"
)

import (
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/hashicorp/go-multierror"
"github.com/lib/pq"
"go.uber.org/atomic"
)

func init() {
Expand Down Expand Up @@ -217,7 +211,7 @@ func (c *CockroachDb) Unlock() error {
}

func (c *CockroachDb) Run(migration io.Reader) error {
migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions database/firebird/firebird.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"context"
"database/sql"
"fmt"
"io"
nurl "net/url"

"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/hashicorp/go-multierror"
_ "github.com/nakagami/firebirdsql"
"go.uber.org/atomic"
"io"
"io/ioutil"
nurl "net/url"
)

func init() {
Expand Down Expand Up @@ -122,7 +122,7 @@ func (f *Firebird) Unlock() error {
}

func (f *Firebird) Run(migration io.Reader) error {
migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
24 changes: 12 additions & 12 deletions database/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package mongodb
import (
"context"
"fmt"
"io"
"net/url"
"os"
"strconv"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/hashicorp/go-multierror"
Expand All @@ -11,12 +17,6 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
"go.uber.org/atomic"
"io"
"io/ioutil"
"net/url"
os "os"
"strconv"
"time"
)

func init() {
Expand Down Expand Up @@ -114,7 +114,7 @@ func WithInstance(instance *mongo.Client, config *Config) (database.Driver, erro
}

func (m *Mongo) Open(dsn string) (database.Driver, error) {
//connstring is experimental package, but it used for parse connection string in mongo.Connect function
// connstring is experimental package, but it used for parse connection string in mongo.Connect function
uri, err := connstring.Parse(dsn)
if err != nil {
return nil, err
Expand Down Expand Up @@ -182,7 +182,7 @@ func (m *Mongo) Open(dsn string) (database.Driver, error) {
return mc, nil
}

//Parse the url param, convert it to boolean
// Parse the url param, convert it to boolean
// returns error if param invalid. returns defaultValue if param not present
func parseBoolean(urlParam string, defaultValue bool) (bool, error) {

Expand All @@ -199,7 +199,7 @@ func parseBoolean(urlParam string, defaultValue bool) (bool, error) {
return defaultValue, nil
}

//Parse the url param, convert it to int
// Parse the url param, convert it to int
// returns error if param invalid. returns defaultValue if param not present
func parseInt(urlParam string, defaultValue int) (int, error) {

Expand Down Expand Up @@ -241,7 +241,7 @@ func (m *Mongo) Version() (version int, dirty bool, err error) {
}

func (m *Mongo) Run(migration io.Reader) error {
migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand All @@ -268,8 +268,8 @@ func (m *Mongo) executeCommandsWithTransaction(ctx context.Context, cmds []bson.
return &database.Error{OrigErr: err, Err: "failed to start transaction"}
}
if err := m.executeCommands(sessionContext, cmds); err != nil {
//When command execution is failed, it's aborting transaction
//If you tried to call abortTransaction, it`s return error that transaction already aborted
// When command execution is failed, it's aborting transaction
// If you tried to call abortTransaction, it`s return error that transaction already aborted
return err
}
if err := sessionContext.CommitTransaction(sessionContext); err != nil {
Expand Down
9 changes: 5 additions & 4 deletions database/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"crypto/x509"
"database/sql"
"fmt"
"go.uber.org/atomic"
"io"
"io/ioutil"
nurl "net/url"
"os"
"strconv"
"strings"

"go.uber.org/atomic"

"github.com/go-sql-driver/mysql"
"github.com/golang-migrate/migrate/v4/database"
"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -154,7 +155,7 @@ func urlToMySQLConfig(url string) (*mysql.Config, error) {
if len(ctls) > 0 {
if _, isBool := readBool(ctls); !isBool && strings.ToLower(ctls) != "skip-verify" {
rootCertPool := x509.NewCertPool()
pem, err := ioutil.ReadFile(parsedParams.Get("x-tls-ca"))
pem, err := os.ReadFile(parsedParams.Get("x-tls-ca"))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -322,7 +323,7 @@ func (m *Mysql) Unlock() error {
}

func (m *Mysql) Run(migration io.Reader) error {
migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
16 changes: 5 additions & 11 deletions database/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"log"
"math/big"
"math/rand"
"net/url"
"os"
"strconv"
"testing"
)

import (
"github.com/dhui/dktest"
"github.com/go-sql-driver/mysql"
"github.com/stretchr/testify/assert"
)

import (
"github.com/golang-migrate/migrate/v4"
dt "github.com/golang-migrate/migrate/v4/database/testing"
"github.com/golang-migrate/migrate/v4/dktesting"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/stretchr/testify/assert"
)

const defaultPort = 3306
Expand Down Expand Up @@ -88,7 +82,7 @@ func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
}

func Test(t *testing.T) {
// mysql.SetLogger(mysql.Logger(log.New(ioutil.Discard, "", log.Ltime)))
// mysql.SetLogger(mysql.Logger(log.New(io.Discard, "", log.Ltime)))

dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
ip, port, err := c.Port(defaultPort)
Expand Down Expand Up @@ -121,7 +115,7 @@ func Test(t *testing.T) {
}

func TestMigrate(t *testing.T) {
// mysql.SetLogger(mysql.Logger(log.New(ioutil.Discard, "", log.Ltime)))
// mysql.SetLogger(mysql.Logger(log.New(io.Discard, "", log.Ltime)))

dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
ip, port, err := c.Port(defaultPort)
Expand Down Expand Up @@ -159,7 +153,7 @@ func TestMigrate(t *testing.T) {
}

func TestMigrateAnsiQuotes(t *testing.T) {
// mysql.SetLogger(mysql.Logger(log.New(ioutil.Discard, "", log.Ltime)))
// mysql.SetLogger(mysql.Logger(log.New(io.Discard, "", log.Ltime)))

dktesting.ParallelTest(t, specsAnsiQuotes, func(t *testing.T, c dktest.ContainerInfo) {
ip, port, err := c.Port(defaultPort)
Expand Down Expand Up @@ -342,7 +336,7 @@ func TestExtractCustomQueryParams(t *testing.T) {
}

func createTmpCert(t *testing.T) string {
tmpCertFile, err := ioutil.TempFile("", "migrate_test_cert")
tmpCertFile, err := os.CreateTemp("", "migrate_test_cert")
if err != nil {
t.Fatal("Failed to create temp cert file:", err)
}
Expand Down
3 changes: 1 addition & 2 deletions database/neo4j/neo4j.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
neturl "net/url"
"strconv"
"sync/atomic"
Expand Down Expand Up @@ -173,7 +172,7 @@ func (n *Neo4j) Run(migration io.Reader) (err error) {
return err
}

body, err := ioutil.ReadAll(migration)
body, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions database/pgx/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
"context"
"database/sql"
"fmt"
"go.uber.org/atomic"
"io"
"io/ioutil"
nurl "net/url"
"regexp"
"strconv"
"strings"
"time"

"go.uber.org/atomic"

"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/golang-migrate/migrate/v4/database/multistmt"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-multierror"
"github.com/jackc/pgconn"
"github.com/jackc/pgerrcode"
_ "github.com/jackc/pgx/v4/stdlib"
Expand Down Expand Up @@ -265,7 +265,7 @@ func (p *Postgres) Run(migration io.Reader) error {
}
return err
}
migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"database/sql"
"fmt"
"io"
"io/ioutil"
nurl "net/url"
"regexp"
"strconv"
Expand Down Expand Up @@ -278,7 +277,7 @@ func (p *Postgres) Run(migration io.Reader) error {
}
return err
}
migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions database/ql/ql.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package ql
import (
"database/sql"
"fmt"
"github.com/hashicorp/go-multierror"
"go.uber.org/atomic"
"io"
"io/ioutil"
nurl "net/url"
"strings"

nurl "net/url"
"github.com/hashicorp/go-multierror"
"go.uber.org/atomic"

"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
Expand Down Expand Up @@ -179,7 +178,7 @@ func (m *Ql) Unlock() error {
return nil
}
func (m *Ql) Run(migration io.Reader) error {
migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions database/redshift/redshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"context"
"database/sql"
"fmt"
"go.uber.org/atomic"
"io"
"io/ioutil"
nurl "net/url"
"strconv"
"strings"

"go.uber.org/atomic"

"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -142,7 +142,7 @@ func (p *Redshift) Unlock() error {
}

func (p *Redshift) Run(migration io.Reader) error {
migr, err := ioutil.ReadAll(migration)
migr, err := io.ReadAll(migration)
if err != nil {
return err
}
Expand Down
Loading