Skip to content

Commit 5c5a66f

Browse files
committed
[upd] re-add
1 parent 7bffc5d commit 5c5a66f

File tree

9 files changed

+224
-285
lines changed

9 files changed

+224
-285
lines changed

.golangci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ version: "2"
22
linters:
33
default: all
44
disable:
5+
- noinlineerr
6+
- wsl_v5
57
- copyloopvar
68
- cyclop
79
- depguard

baked_in.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"os"
1818
"reflect"
1919
"runtime"
20+
"slices"
2021
"strconv"
2122
"strings"
2223
"sync"
@@ -304,12 +305,7 @@ func isOneOf(fl FieldLevel) bool {
304305
default:
305306
panic(fmt.Sprintf("Bad field type %s", field.Type()))
306307
}
307-
for i := 0; i < len(vals); i++ {
308-
if vals[i] == v {
309-
return true
310-
}
311-
}
312-
return false
308+
return slices.Contains(vals, v)
313309
}
314310

315311
// isOneOfCI is the validation function for validating if the current field's value is one of the provided string values (case insensitive).
@@ -657,7 +653,7 @@ func isISBN13(fl FieldLevel) bool {
657653

658654
factor := []int32{1, 3}
659655

660-
for i = 0; i < 12; i++ {
656+
for i = range int32(12) {
661657
checksum += factor[i%2] * int32(s[i]-'0')
662658
}
663659

@@ -675,7 +671,7 @@ func isISBN10(fl FieldLevel) bool {
675671
var checksum int32
676672
var i int32
677673

678-
for i = 0; i < 9; i++ {
674+
for i = range int32(9) {
679675
checksum += (i + 1) * int32(s[i]-'0')
680676
}
681677

@@ -700,7 +696,7 @@ func isISSN(fl FieldLevel) bool {
700696
pos := 8
701697
checksum := 0
702698

703-
for i := 0; i < 7; i++ {
699+
for i := range 7 {
704700
checksum += pos * int(s[i]-'0')
705701
pos--
706702
}
@@ -832,7 +828,7 @@ func isBitcoinBech32Address(fl FieldLevel) bool {
832828
b := p >> 25
833829
p = (p&0x1ffffff)<<5 ^ v
834830

835-
for i := 0; i < 5; i++ {
831+
for i := range 5 {
836832
if (b>>uint(i))&1 == 1 {
837833
p ^= GEN[i]
838834
}
@@ -3096,8 +3092,8 @@ func isSpiceDB(fl FieldLevel) bool {
30963092
func isCreditCard(fl FieldLevel) bool {
30973093
val := fl.Field().String()
30983094
var creditCard bytes.Buffer
3099-
segments := strings.Split(val, " ")
3100-
for _, segment := range segments {
3095+
segments := strings.SplitSeq(val, " ")
3096+
for segment := range segments {
31013097
if len(segment) < 3 {
31023098
return false
31033099
}
@@ -3195,7 +3191,7 @@ func tryCallValidateFn(field reflect.Value, validateFn string) (bool, error) {
31953191
case reflect.Bool:
31963192
return firstReturnValue.Bool(), nil
31973193
case reflect.Interface:
3198-
errorType := reflect.TypeOf((*error)(nil)).Elem()
3194+
errorType := reflect.TypeFor[error]()
31993195

32003196
if firstReturnValue.Type().Implements(errorType) {
32013197
return firstReturnValue.IsNil(), nil

0 commit comments

Comments
 (0)