Skip to content

Commit

Permalink
handle pq.StringArray with isUnique
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz0707 committed Nov 26, 2024
1 parent 6c3307e commit 359fe50
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions baked_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/gabriel-vasile/mimetype"
urn "github.com/leodido/go-urn"
"github.com/lib/pq"
)

// Func accepts a FieldLevel interface for all validation needs. The return
Expand Down Expand Up @@ -326,6 +327,11 @@ func isUnique(fl FieldLevel) bool {

switch field.Kind() {
case reflect.Slice, reflect.Array:
// If it's a pq.StringArray, convert it to a []string for easier handling
if field.Type() == reflect.TypeOf(pq.StringArray{}) {
field = reflect.ValueOf([]string(field.Interface().(pq.StringArray)))
}

elem := field.Type().Elem()
if elem.Kind() == reflect.Ptr {
elem = elem.Elem()
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
github.com/leodido/go-urn v1.4.0
github.com/lib/pq v1.10.9
golang.org/x/crypto v0.19.0
golang.org/x/text v0.14.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
Expand Down

0 comments on commit 359fe50

Please sign in to comment.