Skip to content

Commit

Permalink
apply suggestion
Browse files Browse the repository at this point in the history
apply suggestion
  • Loading branch information
jiuker committed Mar 25, 2024
1 parent ba50c2d commit f79d815
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/job-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
Expand Down
36 changes: 18 additions & 18 deletions pkg/utils/miniojob/minioJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
}
Expand All @@ -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")
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/miniojob/minioJob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f79d815

Please sign in to comment.