Skip to content

Commit

Permalink
Merge pull request #755 from abhinavnair/replace-ioutil
Browse files Browse the repository at this point in the history
Replace deprecated ioutil pkg with os & io
  • Loading branch information
dhui authored Jul 27, 2022
2 parents fca5869 + 885d03c commit eebc4c4
Show file tree
Hide file tree
Showing 35 changed files with 109 additions and 139 deletions.
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

0 comments on commit eebc4c4

Please sign in to comment.