From f79d8154e3c7e69c2fa88c008570a96068864adb Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Mon, 25 Mar 2024 11:10:37 +0800 Subject: [PATCH] apply suggestion apply suggestion --- pkg/controller/job-controller.go | 2 +- pkg/utils/miniojob/minioJob.go | 36 ++++++++++++++--------------- pkg/utils/miniojob/minioJob_test.go | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/controller/job-controller.go b/pkg/controller/job-controller.go index 0800e479602..fc2244701d9 100644 --- a/pkg/controller/job-controller.go +++ b/pkg/controller/job-controller.go @@ -69,7 +69,7 @@ var operationAlias = map[string]string{ "admin/policy/add": "admin/policy/create", } -var jobOperation = map[string][]miniojob.FiledsFunc{ +var jobOperation = map[string][]miniojob.FieldsFunc{ "mb": {miniojob.FLAGS(), miniojob.NoSpace(miniojob.ALIAS(), miniojob.Static("/"), miniojob.Key("name")), miniojob.Static("--ignore-existing")}, "admin/user/add": {miniojob.ALIAS(), miniojob.Key("user"), miniojob.Key("password")}, "admin/policy/create": {miniojob.ALIAS(), miniojob.Key("name"), miniojob.File("policy", "json")}, diff --git a/pkg/utils/miniojob/minioJob.go b/pkg/utils/miniojob/minioJob.go index 8f518317e4e..84c6ea9e112 100644 --- a/pkg/utils/miniojob/minioJob.go +++ b/pkg/utils/miniojob/minioJob.go @@ -35,55 +35,55 @@ func (arg Arg) IsFile() bool { return arg.FileName != "" } -// FiledsFunc - alias function -type FiledsFunc func(args map[string]string) (Arg, error) +// FieldsFunc - alias function +type FieldsFunc func(args map[string]string) (Arg, error) // Key - key=value -func Key(key string) FiledsFunc { +func Key(key string) FieldsFunc { return KeyForamt(key, "$0") } // FLAGS - --key=value|value1,value2,value3 -func FLAGS(igrnoreKeys ...string) FiledsFunc { - return prefixKeyForamt("-", igrnoreKeys...) +func FLAGS(ignoreKeys ...string) FieldsFunc { + return prefixKeyForamt("-", ignoreKeys...) } // ALIAS - myminio -func ALIAS() FiledsFunc { +func ALIAS() FieldsFunc { return Static("myminio") } // Static - some static value -func Static(val string) FiledsFunc { +func Static(val string) FieldsFunc { return func(args map[string]string) (Arg, error) { return Arg{Command: val}, nil } } // File - file key, ext -func File(fkey string, ext string) FiledsFunc { +func File(fName string, ext string) FieldsFunc { return func(args map[string]string) (out Arg, err error) { if args == nil { return out, fmt.Errorf("args is nil") } for key, val := range args { - if key == fkey { + if key == fName { if val == "" { return out, fmt.Errorf("value is empty") } - out.FileName = fkey + out.FileName = fName out.FileExt = ext out.FileContext = strings.TrimSpace(val) return out, nil } } - return out, fmt.Errorf("key %s not found", fkey) + return out, fmt.Errorf("file %s not found", fName) } } // KeyForamt - key,outPut // if format not contain $0, will add $0 to the end -func KeyForamt(key string, format string) FiledsFunc { +func KeyForamt(key string, format string) FieldsFunc { return func(args map[string]string) (out Arg, err error) { if args == nil { return out, fmt.Errorf("args is nil") @@ -101,13 +101,13 @@ func KeyForamt(key string, format string) FiledsFunc { } // OneOf - one of the funcs must be found -func OneOf(funcs ...FiledsFunc) FiledsFunc { +func OneOf(funcs ...FieldsFunc) FieldsFunc { return func(args map[string]string) (out Arg, err error) { if args == nil { return out, fmt.Errorf("args is nil") } - for _, func1 := range funcs { - if out, err = func1(args); err == nil { + for _, fn := range funcs { + if out, err = fn(args); err == nil { return out, nil } } @@ -116,7 +116,7 @@ func OneOf(funcs ...FiledsFunc) FiledsFunc { } // NoSpace - no space for the command -func NoSpace(funcs ...FiledsFunc) FiledsFunc { +func NoSpace(funcs ...FieldsFunc) FieldsFunc { return func(args map[string]string) (out Arg, err error) { if args == nil { return out, fmt.Errorf("args is nil") @@ -135,13 +135,13 @@ func NoSpace(funcs ...FiledsFunc) FiledsFunc { } } -var prefixKeyForamt = func(pkey string, igrnoreKeys ...string) FiledsFunc { +var prefixKeyForamt = func(pkey string, ignoreKeys ...string) FieldsFunc { return func(args map[string]string) (out Arg, err error) { if args == nil { return out, fmt.Errorf("args is nil") } igrnoreKeyMap := make(map[string]bool) - for _, key := range igrnoreKeys { + for _, key := range ignoreKeys { if !strings.HasPrefix(key, pkey) { key = fmt.Sprintf("%s%s%s", pkey, pkey, key) } diff --git a/pkg/utils/miniojob/minioJob_test.go b/pkg/utils/miniojob/minioJob_test.go index 3311d6a2408..5cec06a62a9 100644 --- a/pkg/utils/miniojob/minioJob_test.go +++ b/pkg/utils/miniojob/minioJob_test.go @@ -44,7 +44,7 @@ func TestParser(t *testing.T) { "name": "mybucketName", } testCase := []struct { - command FiledsFunc + command FieldsFunc args map[string]string expect Arg expectError bool