Browse Source

refactor and fix strings.Split

pull/3415/head
chrislu 2 years ago
parent
commit
67814a5c79
  1. 3
      weed/command/filer_backup.go
  2. 4
      weed/command/filer_sync.go
  3. 5
      weed/command/master.go
  4. 6
      weed/command/server.go
  5. 4
      weed/command/volume.go
  6. 3
      weed/s3api/tags.go
  7. 3
      weed/shell/shell_liner.go
  8. 2
      weed/util/fullpath.go

3
weed/command/filer_backup.go

@ -8,7 +8,6 @@ import (
"github.com/seaweedfs/seaweedfs/weed/security" "github.com/seaweedfs/seaweedfs/weed/security"
"github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/util"
"google.golang.org/grpc" "google.golang.org/grpc"
"strings"
"time" "time"
) )
@ -87,7 +86,7 @@ func doFilerBackup(grpcDialOption grpc.DialOption, backupOption *FilerBackupOpti
sourceFiler := pb.ServerAddress(*backupOption.filer) sourceFiler := pb.ServerAddress(*backupOption.filer)
sourcePath := *backupOption.path sourcePath := *backupOption.path
excludePaths := strings.Split(*backupOption.excludePaths, ",")
excludePaths := util.StringSplit(*backupOption.excludePaths, ",")
timeAgo := *backupOption.timeAgo timeAgo := *backupOption.timeAgo
targetPath := dataSink.GetSinkToDirectory() targetPath := dataSink.GetSinkToDirectory()
debug := *backupOption.debug debug := *backupOption.debug

4
weed/command/filer_sync.go

@ -143,7 +143,7 @@ func runFilerSynchronize(cmd *Command, args []string) bool {
grpcDialOption, grpcDialOption,
filerA, filerA,
*syncOptions.aPath, *syncOptions.aPath,
util.Split(*syncOptions.aExcludePaths, ","),
util.StringSplit(*syncOptions.aExcludePaths, ","),
*syncOptions.aProxyByFiler, *syncOptions.aProxyByFiler,
filerB, filerB,
*syncOptions.bPath, *syncOptions.bPath,
@ -179,7 +179,7 @@ func runFilerSynchronize(cmd *Command, args []string) bool {
grpcDialOption, grpcDialOption,
filerB, filerB,
*syncOptions.bPath, *syncOptions.bPath,
util.Split(*syncOptions.bExcludePaths, ","),
util.StringSplit(*syncOptions.bExcludePaths, ","),
*syncOptions.bProxyByFiler, *syncOptions.bProxyByFiler,
filerA, filerA,
*syncOptions.aPath, *syncOptions.aPath,

5
weed/command/master.go

@ -113,10 +113,7 @@ func runMaster(cmd *Command, args []string) bool {
glog.Fatalf("Check Meta Folder (-mdir) Writable %s : %s", *m.metaFolder, err) glog.Fatalf("Check Meta Folder (-mdir) Writable %s : %s", *m.metaFolder, err)
} }
var masterWhiteList []string
if *m.whiteList != "" {
masterWhiteList = strings.Split(*m.whiteList, ",")
}
masterWhiteList := util.StringSplit(*m.whiteList, ",")
if *m.volumeSizeLimitMB > util.VolumeSizeLimitGB*1000 { if *m.volumeSizeLimitMB > util.VolumeSizeLimitGB*1000 {
glog.Fatalf("volumeSizeLimitMB should be smaller than 30000") glog.Fatalf("volumeSizeLimitMB should be smaller than 30000")
} }

6
weed/command/server.go

@ -76,8 +76,6 @@ var (
isStartingWebDav = cmdServer.Flag.Bool("webdav", false, "whether to start WebDAV gateway") isStartingWebDav = cmdServer.Flag.Bool("webdav", false, "whether to start WebDAV gateway")
isStartingMqBroker = cmdServer.Flag.Bool("mq.broker", false, "whether to start message queue broker") isStartingMqBroker = cmdServer.Flag.Bool("mq.broker", false, "whether to start message queue broker")
serverWhiteList []string
False = false False = false
) )
@ -248,9 +246,7 @@ func runServer(cmd *Command, args []string) bool {
} }
filerOptions.defaultLevelDbDirectory = masterOptions.metaFolder filerOptions.defaultLevelDbDirectory = masterOptions.metaFolder
if *serverWhiteListOption != "" {
serverWhiteList = strings.Split(*serverWhiteListOption, ",")
}
serverWhiteList := util.StringSplit(*serverWhiteListOption, ",")
if *isStartingFiler { if *isStartingFiler {
go func() { go func() {

4
weed/command/volume.go

@ -188,9 +188,7 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
} }
// security related white list configuration // security related white list configuration
if volumeWhiteListOption != "" {
v.whiteList = strings.Split(volumeWhiteListOption, ",")
}
v.whiteList = util.StringSplit(volumeWhiteListOption, ",")
if *v.ip == "" { if *v.ip == "" {
*v.ip = util.DetectedHostAddress() *v.ip = util.DetectedHostAddress()

3
weed/s3api/tags.go

@ -3,6 +3,7 @@ package s3api
import ( import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"github.com/seaweedfs/seaweedfs/weed/util"
"regexp" "regexp"
"strings" "strings"
) )
@ -43,7 +44,7 @@ func FromTags(tags map[string]string) (t *Tagging) {
func parseTagsHeader(tags string) (map[string]string, error) { func parseTagsHeader(tags string) (map[string]string, error) {
parsedTags := make(map[string]string) parsedTags := make(map[string]string)
for _, v := range strings.Split(tags, "&") {
for _, v := range util.StringSplit(tags, "&") {
tag := strings.Split(v, "=") tag := strings.Split(v, "=")
if len(tag) == 2 { if len(tag) == 2 {
parsedTags[tag[0]] = tag[1] parsedTags[tag[0]] = tag[1]

3
weed/shell/shell_liner.go

@ -7,6 +7,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
"github.com/seaweedfs/seaweedfs/weed/util/grace" "github.com/seaweedfs/seaweedfs/weed/util/grace"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"io" "io"
@ -100,7 +101,7 @@ https://cloud.seaweedfs.com/ui/%s
return return
} }
for _, c := range strings.Split(cmd, ";") {
for _, c := range util.StringSplit(cmd, ";") {
if processEachCmd(reg, c, commandEnv) { if processEachCmd(reg, c, commandEnv) {
return return
} }

2
weed/util/fullpath.go

@ -71,7 +71,7 @@ func (fp FullPath) IsUnder(other FullPath) bool {
return strings.HasPrefix(string(fp), string(other)+"/") return strings.HasPrefix(string(fp), string(other)+"/")
} }
func Split(separatedValues string, sep string) []string {
func StringSplit(separatedValues string, sep string) []string {
if separatedValues == "" { if separatedValues == "" {
return nil return nil
} }

Loading…
Cancel
Save