asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.06k stars 556 forks source link

Add ULID validator #437

Closed elipavlov closed 3 years ago

elipavlov commented 3 years ago
Q A
Documentation no
Bugfix no
BC Break no
New Feature yes
RFC no
QA yes

Description

It adds a validator for the ULID format.

I'm going to add support for this string format to go swagger library. Since strfmt uses this library I've decided to start from here.

elipavlov commented 3 years ago

It has switched to index array implementation which borrowed from a library which mentioned in commit message and comments of the actual change.

Benchmark comparison is here: https://github.com/elipavlov/govalidator/pull/1

go test -bench BenchmarkIsULID -benchmem
pkg: github.com/asaskevich/govalidator
BenchmarkIsULID_RE-4     4085954           281 ns/op      92.41 MB/s           0 B/op          0 allocs/op
BenchmarkIsULID-4       60308574            17.5 ns/op  1482.27 MB/s           0 B/op          0 allocs/op
PASS
ok      github.com/asaskevich/govalidator   2.880s
asaskevich commented 3 years ago

Thank you!