Skip to content

Commit

Permalink
typed field mask
Browse files Browse the repository at this point in the history
  • Loading branch information
sxwebdev committed Feb 18, 2024
1 parent 97043c4 commit 72fed29
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/db/dbutils/field_mask.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package dbutils

import "slices"

type FieldMask []string
type FieldMask[T ~string] []T

func (s *FieldMask) Add(items ...string) []string {
func (s *FieldMask[T]) Add(items ...T) []T {
if s == nil {
*s = make([]string, 0)
*s = make([]T, 0)
}

if len(items) == 0 {
Expand All @@ -22,17 +22,17 @@ func (s *FieldMask) Add(items ...string) []string {
return *s
}

func (s FieldMask) Items() []string {
func (s FieldMask[T]) Items() []T {
if s == nil {
return FieldMask{}
return FieldMask[T]{}
}
return s
}

func (s FieldMask) Len() int {
func (s FieldMask[T]) Len() int {
return len(s)
}

func (s FieldMask) Contains(v string) bool {
func (s FieldMask[T]) Contains(v T) bool {
return slices.Contains(s, v)
}

0 comments on commit 72fed29

Please sign in to comment.