From e1b3a9f60e944f9514c28e0305b7cb747ee7418c Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Mon, 18 Dec 2023 22:03:31 +0800 Subject: [PATCH] chore: Format the import order --- cmd/redis-shake/main.go | 4 +++- internal/client/func.go | 5 +++-- internal/client/redis.go | 5 +++-- internal/commands/keys.go | 5 +++-- internal/config/config.go | 8 +++++--- internal/entry/entry.go | 5 +++-- internal/function/function.go | 4 +++- internal/log/func.go | 3 ++- internal/log/init.go | 3 ++- internal/rdb/rdb.go | 13 +++++++------ internal/rdb/structure/byte.go | 3 ++- internal/rdb/structure/float.go | 3 ++- internal/rdb/structure/length.go | 3 ++- internal/rdb/structure/listpack.go | 3 ++- internal/rdb/structure/string.go | 3 ++- internal/rdb/structure/ziplist.go | 3 ++- internal/rdb/types/hash.go | 3 ++- internal/rdb/types/interface.go | 3 ++- internal/rdb/types/list.go | 3 ++- internal/rdb/types/mbbloom.go | 5 +++-- internal/rdb/types/set.go | 3 ++- internal/rdb/types/stream.go | 5 +++-- internal/rdb/types/string.go | 3 ++- internal/rdb/types/zset.go | 5 +++-- internal/reader/aof_reader.go | 5 +++-- internal/reader/parsing_aof.go | 7 ++++--- internal/reader/rdb_reader.go | 4 +++- internal/reader/scan_cluster_reader.go | 5 +++-- internal/reader/scan_standalone_reader.go | 11 ++++++----- internal/reader/sync_cluster_reader.go | 5 +++-- internal/reader/sync_standalone_reader.go | 18 ++++++++++-------- internal/status/handler.go | 5 +++-- internal/status/status.go | 3 ++- internal/utils/cluster_nodes.go | 5 +++-- internal/utils/file.go | 3 ++- internal/utils/file_rotate/aof_reader.go | 5 +++-- internal/utils/file_rotate/aof_writer.go | 3 ++- internal/utils/filelock.go | 6 ++++-- internal/utils/ncpu.go | 3 ++- internal/utils/pprof.go | 5 +++-- internal/writer/redis_standalone_writer.go | 11 ++++++----- 41 files changed, 127 insertions(+), 80 deletions(-) diff --git a/cmd/redis-shake/main.go b/cmd/redis-shake/main.go index ed5700c5..874dc83b 100644 --- a/cmd/redis-shake/main.go +++ b/cmd/redis-shake/main.go @@ -1,6 +1,8 @@ package main import ( + _ "net/http/pprof" + "RedisShake/internal/config" "RedisShake/internal/function" "RedisShake/internal/log" @@ -8,8 +10,8 @@ import ( "RedisShake/internal/status" "RedisShake/internal/utils" "RedisShake/internal/writer" + "github.com/mcuadros/go-defaults" - _ "net/http/pprof" ) func main() { diff --git a/internal/client/func.go b/internal/client/func.go index 9195683a..1957e153 100644 --- a/internal/client/func.go +++ b/internal/client/func.go @@ -1,10 +1,11 @@ package client import ( - "RedisShake/internal/client/proto" - "RedisShake/internal/log" "bytes" "strings" + + "RedisShake/internal/client/proto" + "RedisShake/internal/log" ) func EncodeArgv(argv []string, buf *bytes.Buffer) { diff --git a/internal/client/redis.go b/internal/client/redis.go index 5c1cb463..848ce90d 100644 --- a/internal/client/redis.go +++ b/internal/client/redis.go @@ -1,13 +1,14 @@ package client import ( - "RedisShake/internal/client/proto" - "RedisShake/internal/log" "bufio" "crypto/tls" "net" "strconv" "time" + + "RedisShake/internal/client/proto" + "RedisShake/internal/log" ) type Redis struct { diff --git a/internal/commands/keys.go b/internal/commands/keys.go index 7d13d21d..be9ab578 100644 --- a/internal/commands/keys.go +++ b/internal/commands/keys.go @@ -1,12 +1,13 @@ package commands import ( - "RedisShake/internal/log" - "RedisShake/internal/utils" "fmt" "math" "strconv" "strings" + + "RedisShake/internal/log" + "RedisShake/internal/utils" ) // CalcKeys https://redis.io/docs/reference/key-specs/ diff --git a/internal/config/config.go b/internal/config/config.go index f55643db..898113a8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,13 +1,15 @@ package config import ( - "RedisShake/internal/log" "fmt" + "os" + "strings" + + "RedisShake/internal/log" + "github.com/mcuadros/go-defaults" "github.com/rs/zerolog" "github.com/spf13/viper" - "os" - "strings" ) type AdvancedOptions struct { diff --git a/internal/entry/entry.go b/internal/entry/entry.go index e81a51d8..9f7cb3fa 100644 --- a/internal/entry/entry.go +++ b/internal/entry/entry.go @@ -1,11 +1,12 @@ package entry import ( + "bytes" + "strings" + "RedisShake/internal/client/proto" "RedisShake/internal/commands" "RedisShake/internal/log" - "bytes" - "strings" ) type Entry struct { diff --git a/internal/function/function.go b/internal/function/function.go index 4a13393d..d1ce39ea 100644 --- a/internal/function/function.go +++ b/internal/function/function.go @@ -1,11 +1,13 @@ package function import ( + "strings" + "RedisShake/internal/config" "RedisShake/internal/entry" "RedisShake/internal/log" + lua "github.com/yuin/gopher-lua" - "strings" ) var luaString string diff --git a/internal/log/func.go b/internal/log/func.go index 2d6aa150..5d778cf2 100644 --- a/internal/log/func.go +++ b/internal/log/func.go @@ -1,8 +1,9 @@ package log import ( - "github.com/go-stack/stack" "os" + + "github.com/go-stack/stack" ) func Debugf(format string, args ...interface{}) { diff --git a/internal/log/init.go b/internal/log/init.go index 0f7d5305..c61b538b 100644 --- a/internal/log/init.go +++ b/internal/log/init.go @@ -2,9 +2,10 @@ package log import ( "fmt" - "github.com/rs/zerolog" "os" "path/filepath" + + "github.com/rs/zerolog" ) var logger zerolog.Logger diff --git a/internal/rdb/rdb.go b/internal/rdb/rdb.go index 81fa05a2..357ba670 100644 --- a/internal/rdb/rdb.go +++ b/internal/rdb/rdb.go @@ -1,12 +1,6 @@ package rdb import ( - "RedisShake/internal/config" - "RedisShake/internal/entry" - "RedisShake/internal/log" - "RedisShake/internal/rdb/structure" - "RedisShake/internal/rdb/types" - "RedisShake/internal/utils" "bufio" "bytes" "encoding/binary" @@ -14,6 +8,13 @@ import ( "os" "strconv" "time" + + "RedisShake/internal/config" + "RedisShake/internal/entry" + "RedisShake/internal/log" + "RedisShake/internal/rdb/structure" + "RedisShake/internal/rdb/types" + "RedisShake/internal/utils" ) const ( diff --git a/internal/rdb/structure/byte.go b/internal/rdb/structure/byte.go index d8b0bed5..f52ae0f5 100644 --- a/internal/rdb/structure/byte.go +++ b/internal/rdb/structure/byte.go @@ -1,8 +1,9 @@ package structure import ( - "RedisShake/internal/log" "io" + + "RedisShake/internal/log" ) func ReadByte(rd io.Reader) byte { diff --git a/internal/rdb/structure/float.go b/internal/rdb/structure/float.go index a254f863..fc1d2b0c 100644 --- a/internal/rdb/structure/float.go +++ b/internal/rdb/structure/float.go @@ -1,11 +1,12 @@ package structure import ( - "RedisShake/internal/log" "encoding/binary" "io" "math" "strconv" + + "RedisShake/internal/log" ) func ReadFloat(rd io.Reader) float64 { diff --git a/internal/rdb/structure/length.go b/internal/rdb/structure/length.go index dc598c08..b0f12bcb 100644 --- a/internal/rdb/structure/length.go +++ b/internal/rdb/structure/length.go @@ -1,10 +1,11 @@ package structure import ( - "RedisShake/internal/log" "encoding/binary" "fmt" "io" + + "RedisShake/internal/log" ) const ( diff --git a/internal/rdb/structure/listpack.go b/internal/rdb/structure/listpack.go index ab4600a5..3c4f9019 100644 --- a/internal/rdb/structure/listpack.go +++ b/internal/rdb/structure/listpack.go @@ -1,12 +1,13 @@ package structure import ( - "RedisShake/internal/log" "bufio" "io" "math" "strconv" "strings" + + "RedisShake/internal/log" ) const ( diff --git a/internal/rdb/structure/string.go b/internal/rdb/structure/string.go index 101148a1..b3327419 100644 --- a/internal/rdb/structure/string.go +++ b/internal/rdb/structure/string.go @@ -1,9 +1,10 @@ package structure import ( - "RedisShake/internal/log" "io" "strconv" + + "RedisShake/internal/log" ) const ( diff --git a/internal/rdb/structure/ziplist.go b/internal/rdb/structure/ziplist.go index 4dcd37f3..a1c47b54 100644 --- a/internal/rdb/structure/ziplist.go +++ b/internal/rdb/structure/ziplist.go @@ -1,12 +1,13 @@ package structure import ( - "RedisShake/internal/log" "bufio" "encoding/binary" "io" "strconv" "strings" + + "RedisShake/internal/log" ) const ( diff --git a/internal/rdb/types/hash.go b/internal/rdb/types/hash.go index 2d373ae6..860017bf 100644 --- a/internal/rdb/types/hash.go +++ b/internal/rdb/types/hash.go @@ -1,9 +1,10 @@ package types import ( + "io" + "RedisShake/internal/log" "RedisShake/internal/rdb/structure" - "io" ) type HashObject struct { diff --git a/internal/rdb/types/interface.go b/internal/rdb/types/interface.go index 04cb96a7..f9502bdc 100644 --- a/internal/rdb/types/interface.go +++ b/internal/rdb/types/interface.go @@ -1,8 +1,9 @@ package types import ( - "RedisShake/internal/log" "io" + + "RedisShake/internal/log" ) const ( diff --git a/internal/rdb/types/list.go b/internal/rdb/types/list.go index 4f6b8dff..3795a58a 100644 --- a/internal/rdb/types/list.go +++ b/internal/rdb/types/list.go @@ -1,9 +1,10 @@ package types import ( + "io" + "RedisShake/internal/log" "RedisShake/internal/rdb/structure" - "io" ) // quicklist node container formats diff --git a/internal/rdb/types/mbbloom.go b/internal/rdb/types/mbbloom.go index 5704c2a0..a6e0c25b 100644 --- a/internal/rdb/types/mbbloom.go +++ b/internal/rdb/types/mbbloom.go @@ -1,11 +1,12 @@ package types import ( - "RedisShake/internal/config" - "RedisShake/internal/rdb/structure" "io" "strconv" "unsafe" + + "RedisShake/internal/config" + "RedisShake/internal/rdb/structure" ) // BloomObject for MBbloom-- at https://github.com/RedisBloom/RedisBloom diff --git a/internal/rdb/types/set.go b/internal/rdb/types/set.go index b66188cd..3ebb9756 100644 --- a/internal/rdb/types/set.go +++ b/internal/rdb/types/set.go @@ -1,9 +1,10 @@ package types import ( + "io" + "RedisShake/internal/log" "RedisShake/internal/rdb/structure" - "io" ) type SetObject struct { diff --git a/internal/rdb/types/stream.go b/internal/rdb/types/stream.go index f1eb7b22..a86cfa68 100644 --- a/internal/rdb/types/stream.go +++ b/internal/rdb/types/stream.go @@ -1,12 +1,13 @@ package types import ( - "RedisShake/internal/log" - "RedisShake/internal/rdb/structure" "encoding/binary" "fmt" "io" "strconv" + + "RedisShake/internal/log" + "RedisShake/internal/rdb/structure" ) /* diff --git a/internal/rdb/types/string.go b/internal/rdb/types/string.go index 6321fd36..25cad699 100644 --- a/internal/rdb/types/string.go +++ b/internal/rdb/types/string.go @@ -1,8 +1,9 @@ package types import ( - "RedisShake/internal/rdb/structure" "io" + + "RedisShake/internal/rdb/structure" ) type StringObject struct { diff --git a/internal/rdb/types/zset.go b/internal/rdb/types/zset.go index 16f1d8a1..68dcf976 100644 --- a/internal/rdb/types/zset.go +++ b/internal/rdb/types/zset.go @@ -1,10 +1,11 @@ package types import ( - "RedisShake/internal/log" - "RedisShake/internal/rdb/structure" "fmt" "io" + + "RedisShake/internal/log" + "RedisShake/internal/rdb/structure" ) type ZSetEntry struct { diff --git a/internal/reader/aof_reader.go b/internal/reader/aof_reader.go index b4631034..f18b9248 100644 --- a/internal/reader/aof_reader.go +++ b/internal/reader/aof_reader.go @@ -1,9 +1,10 @@ package reader import ( - "RedisShake/internal/aof" "path/filepath" + "RedisShake/internal/aof" + "RedisShake/internal/entry" "RedisShake/internal/log" "RedisShake/internal/utils" @@ -101,4 +102,4 @@ func (r *aofReader) StartRead() chan *entry.Entry { }() return r.ch -} \ No newline at end of file +} diff --git a/internal/reader/parsing_aof.go b/internal/reader/parsing_aof.go index e6ca00fd..06865cfd 100644 --- a/internal/reader/parsing_aof.go +++ b/internal/reader/parsing_aof.go @@ -1,9 +1,6 @@ package reader import ( - "RedisShake/internal/aof" - "RedisShake/internal/entry" - "RedisShake/internal/log" "bufio" "bytes" "container/list" @@ -16,6 +13,10 @@ import ( "strings" "time" "unicode" + + "RedisShake/internal/aof" + "RedisShake/internal/entry" + "RedisShake/internal/log" ) const ( diff --git a/internal/reader/rdb_reader.go b/internal/reader/rdb_reader.go index 23b5a30f..0088880c 100644 --- a/internal/reader/rdb_reader.go +++ b/internal/reader/rdb_reader.go @@ -1,11 +1,13 @@ package reader import ( + "fmt" + "RedisShake/internal/entry" "RedisShake/internal/log" "RedisShake/internal/rdb" "RedisShake/internal/utils" - "fmt" + "github.com/dustin/go-humanize" ) diff --git a/internal/reader/scan_cluster_reader.go b/internal/reader/scan_cluster_reader.go index 3a3f1151..133942e6 100644 --- a/internal/reader/scan_cluster_reader.go +++ b/internal/reader/scan_cluster_reader.go @@ -1,10 +1,11 @@ package reader import ( - "RedisShake/internal/entry" - "RedisShake/internal/utils" "fmt" "sync" + + "RedisShake/internal/entry" + "RedisShake/internal/utils" ) type scanClusterReader struct { diff --git a/internal/reader/scan_standalone_reader.go b/internal/reader/scan_standalone_reader.go index dc21a396..81d62741 100644 --- a/internal/reader/scan_standalone_reader.go +++ b/internal/reader/scan_standalone_reader.go @@ -1,6 +1,12 @@ package reader import ( + "fmt" + "math/bits" + "regexp" + "strconv" + "strings" + "RedisShake/internal/client" "RedisShake/internal/client/proto" "RedisShake/internal/config" @@ -8,11 +14,6 @@ import ( "RedisShake/internal/log" "RedisShake/internal/rdb/types" "RedisShake/internal/utils" - "fmt" - "math/bits" - "regexp" - "strconv" - "strings" ) type ScanReaderOptions struct { diff --git a/internal/reader/sync_cluster_reader.go b/internal/reader/sync_cluster_reader.go index 0a98be5f..b8a44de0 100644 --- a/internal/reader/sync_cluster_reader.go +++ b/internal/reader/sync_cluster_reader.go @@ -1,11 +1,12 @@ package reader import ( + "fmt" + "sync" + "RedisShake/internal/entry" "RedisShake/internal/log" "RedisShake/internal/utils" - "fmt" - "sync" ) type syncClusterReader struct { diff --git a/internal/reader/sync_standalone_reader.go b/internal/reader/sync_standalone_reader.go index fc969702..c68603d4 100644 --- a/internal/reader/sync_standalone_reader.go +++ b/internal/reader/sync_standalone_reader.go @@ -1,22 +1,24 @@ package reader import ( - "RedisShake/internal/client" - "RedisShake/internal/config" - "RedisShake/internal/entry" - "RedisShake/internal/log" - "RedisShake/internal/rdb" - "RedisShake/internal/utils" - "RedisShake/internal/utils/file_rotate" "bufio" "fmt" - "github.com/dustin/go-humanize" "io" "os" "path/filepath" "strconv" "strings" "time" + + "RedisShake/internal/client" + "RedisShake/internal/config" + "RedisShake/internal/entry" + "RedisShake/internal/log" + "RedisShake/internal/rdb" + "RedisShake/internal/utils" + "RedisShake/internal/utils/file_rotate" + + "github.com/dustin/go-humanize" ) type SyncReaderOptions struct { diff --git a/internal/status/handler.go b/internal/status/handler.go index c0069cf8..facd5575 100644 --- a/internal/status/handler.go +++ b/internal/status/handler.go @@ -1,12 +1,13 @@ package status import ( - "RedisShake/internal/config" - "RedisShake/internal/log" "encoding/json" "fmt" "net/http" "time" + + "RedisShake/internal/config" + "RedisShake/internal/log" ) func Handler(w http.ResponseWriter, _ *http.Request) { diff --git a/internal/status/status.go b/internal/status/status.go index a83a4412..dfc66c19 100644 --- a/internal/status/status.go +++ b/internal/status/status.go @@ -1,9 +1,10 @@ package status import ( + "time" + "RedisShake/internal/config" "RedisShake/internal/log" - "time" ) type Statusable interface { diff --git a/internal/utils/cluster_nodes.go b/internal/utils/cluster_nodes.go index d98ad643..56d26b7d 100644 --- a/internal/utils/cluster_nodes.go +++ b/internal/utils/cluster_nodes.go @@ -1,11 +1,12 @@ package utils import ( - "RedisShake/internal/client" - "RedisShake/internal/log" "fmt" "strconv" "strings" + + "RedisShake/internal/client" + "RedisShake/internal/log" ) func GetRedisClusterNodes(address string, username string, password string, Tls bool) (addresses []string, slots [][]int) { diff --git a/internal/utils/file.go b/internal/utils/file.go index 28d3fec5..fd218d0e 100644 --- a/internal/utils/file.go +++ b/internal/utils/file.go @@ -1,9 +1,10 @@ package utils import ( - "RedisShake/internal/log" "os" "path/filepath" + + "RedisShake/internal/log" ) func CreateEmptyDir(dir string) { diff --git a/internal/utils/file_rotate/aof_reader.go b/internal/utils/file_rotate/aof_reader.go index 1d82d20d..3c330944 100644 --- a/internal/utils/file_rotate/aof_reader.go +++ b/internal/utils/file_rotate/aof_reader.go @@ -1,12 +1,13 @@ package rotate import ( - "RedisShake/internal/log" - "RedisShake/internal/utils" "fmt" "io" "os" "time" + + "RedisShake/internal/log" + "RedisShake/internal/utils" ) type AOFReader struct { diff --git a/internal/utils/file_rotate/aof_writer.go b/internal/utils/file_rotate/aof_writer.go index 18c12b86..17647eff 100644 --- a/internal/utils/file_rotate/aof_writer.go +++ b/internal/utils/file_rotate/aof_writer.go @@ -1,9 +1,10 @@ package rotate import ( - "RedisShake/internal/log" "fmt" "os" + + "RedisShake/internal/log" ) const MaxFileSize = 1024 * 1024 * 1024 // 1G diff --git a/internal/utils/filelock.go b/internal/utils/filelock.go index 69b1acb4..4b491f68 100644 --- a/internal/utils/filelock.go +++ b/internal/utils/filelock.go @@ -1,11 +1,13 @@ package utils import ( + "os" + "path/filepath" + "RedisShake/internal/config" "RedisShake/internal/log" + "github.com/theckman/go-flock" - "os" - "path/filepath" ) var filelock *flock.Flock diff --git a/internal/utils/ncpu.go b/internal/utils/ncpu.go index ba3c502e..ce487852 100644 --- a/internal/utils/ncpu.go +++ b/internal/utils/ncpu.go @@ -1,9 +1,10 @@ package utils import ( + "runtime" + "RedisShake/internal/config" "RedisShake/internal/log" - "runtime" ) func SetNcpu() { diff --git a/internal/utils/pprof.go b/internal/utils/pprof.go index a7884307..79b3a716 100644 --- a/internal/utils/pprof.go +++ b/internal/utils/pprof.go @@ -1,10 +1,11 @@ package utils import ( - "RedisShake/internal/config" - "RedisShake/internal/log" "fmt" "net/http" + + "RedisShake/internal/config" + "RedisShake/internal/log" ) func SetPprofPort() { diff --git a/internal/writer/redis_standalone_writer.go b/internal/writer/redis_standalone_writer.go index f4f57e3c..734670c6 100644 --- a/internal/writer/redis_standalone_writer.go +++ b/internal/writer/redis_standalone_writer.go @@ -1,17 +1,18 @@ package writer import ( - "RedisShake/internal/client" - "RedisShake/internal/client/proto" - "RedisShake/internal/config" - "RedisShake/internal/entry" - "RedisShake/internal/log" "fmt" "strconv" "strings" "sync" "sync/atomic" "time" + + "RedisShake/internal/client" + "RedisShake/internal/client/proto" + "RedisShake/internal/config" + "RedisShake/internal/entry" + "RedisShake/internal/log" ) type RedisWriterOptions struct {