diff --git a/go.mod b/go.mod index b15cdd7..96afcb7 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.fsdpf.net/go/contracts -go 1.18 +go 1.21 require ( git.fsdpf.net/go/db v0.0.0-20230621051209-5740d112407f diff --git a/support/list.go b/support/list.go index ed7f002..856fe3b 100644 --- a/support/list.go +++ b/support/list.go @@ -5,6 +5,7 @@ import ( "reflect" "git.fsdpf.net/go/contracts" + "github.com/samber/lo" "github.com/spf13/cast" ) @@ -36,7 +37,7 @@ func (this *OperationAccess) Push(k string, input ...any) error { for i := 0; i < len(input); i++ { if v, err := this.Convert(input[i]); err != nil { return err - } else { + } else if !lo.Contains(this.data[k], v) { this.data[k] = append(this.data[k], v) } } @@ -44,6 +45,13 @@ func (this *OperationAccess) Push(k string, input ...any) error { return nil } +func (this OperationAccess) Merge(item OperationAccess) error { + for k, v := range item.data { + this.Push(k, v...) + } + return nil +} + func (this OperationAccess) Convert(v any) (any, error) { if this.typ == reflect.Int { return cast.ToIntE(v) @@ -64,13 +72,7 @@ func (this OperationAccess) Exist(k string, v any) bool { return false } - for i := 0; i < len(items); i++ { - if items[i] == flag { - return true - } - } - - return false + return lo.Contains(items, flag) } func (this OperationAccess) MarshalJSON() ([]byte, error) {