Skip to content

Commit

Permalink
update ioutil and rand pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
dobet committed Jul 18, 2023
1 parent cb9f5ae commit 355237f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/config/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package config

import (
"io/ioutil"
"os"
"path/filepath"
)

Expand All @@ -35,7 +35,7 @@ import (

// LoadBootOptions loads BootOptions from specified file path.
func LoadBootOptions(path string) (*BootOptions, error) {
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
err = errors.Wrap(err, "failed to load config")
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/mysql/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ func strconvErr(err error) error {
// RandomBuf return random salt, seed must be in the range of ascii
func RandomBuf(size int) ([]byte, error) {
buf := make([]byte, size)
rand.Seed(time.Now().UTC().UnixNano())
rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
min, max := 30, 127
for i := 0; i < size; i++ {
buf[i] = byte(min + rand.Intn(max-min))
Expand Down
4 changes: 2 additions & 2 deletions pkg/runtime/function/cast_char.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package function
import (
"bytes"
"context"
"io/ioutil"
"io"
"strings"
"unicode/utf8"
)
Expand Down Expand Up @@ -187,7 +187,7 @@ func (a castcharFunc) getResult(runes []rune, num int64, charEncode string) (str
// UTF-16 bigendian, no-bom
trans := transform.NewReader(srcReader,
unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewEncoder())
dstString, err := ioutil.ReadAll(trans)
dstString, err := io.ReadAll(trans)
if err == nil {
return string(dstString), nil
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/selector/weight_random.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type weightRandom struct {
}

func init() {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
}

func (w weightRandom) GetDataSourceNo() int {
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/charsetconv/charsetconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package charsetconv

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

Expand Down Expand Up @@ -99,7 +99,7 @@ func GetCharset(charset string) (Charset, error) {

func transformString(t transform.Transformer, s string) (string, error) {
r := transform.NewReader(strings.NewReader(s), t)
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
return string(b), err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/util/rand2/rand2.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ func GetSeed() int64 {
}

func init() {
rand.Seed(GetSeed())
rand.New(rand.NewSource(GetSeed()))
}

var (
// See math/rand for documentation.
New = rand.New

// See math/rand for documentation.
Seed = rand.Seed
Seed = rand.New

// See math/rand for documentation.
Int63 = rand.Int63
Expand Down

0 comments on commit 355237f

Please sign in to comment.