Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ updates:
- package-ecosystem: gomod
directories:
- "/"
- "/uuid"
- "/rules/uuid"
- "/huma"
- "/gin"
- "/echo"
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: |
. scripts/modules.sh
for module in $MODULES; do
(cd "$module" && golangci-lint run --config ../.golangci.yml ./...)
(cd "$module" && golangci-lint run --config "$GITHUB_WORKSPACE/.golangci.yml" ./...)
done

test:
Expand All @@ -45,6 +45,7 @@ jobs:
cache-dependency-path: |
go.sum
*/go.sum
rules/*/go.sum

- name: Build
run: |
Expand All @@ -63,8 +64,9 @@ jobs:
. scripts/modules.sh
files=./coverage.txt
for module in $MODULES; do
(cd "$module" && go test -v -race -coverprofile="../coverage-$module.txt" -covermode=atomic ./...)
files="$files,./coverage-$module.txt"
name="coverage-${module//\//-}.txt"
(cd "$module" && go test -v -race -coverprofile="$OLDPWD/$name" -covermode=atomic ./...)
files="$files,./$name"
done
echo "coverage=$files" >> "$GITHUB_OUTPUT"

Expand All @@ -87,7 +89,7 @@ jobs:
go-version: '1.27'
cache-dependency-path: |
go.sum
uuid/go.sum
rules/uuid/go.sum
huma/go.sum
examples/*/go.sum

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ and a conversion that doesn't fit the field doesn't compile:
| `num.Of`, `num.Ptr` | integers, floats, named numbers, pointers to them | `Required`, `Min`, `Max`, `AnyOf`, `AnyOfInterval`, `Latitude`, `Longitude` |
| `timex.Of` | `time.Time`, `*time.Time` | `Required`, `Before`, `After`, `Between`, `InPast`, `InFuture` |
| `eq.Of`, `eq.Ptr` | any `comparable`: enums, bools | `Required`, `OneOf`, `NotOneOf`, `Equal`, `NotEqual` |
| `vuuid.Of` | `uuid.UUID`, `*uuid.UUID`, the separate module `github.com/insei/valigo/uuid` | `Required`, `AnyOf` |
| `vuuid.Of` | `uuid.UUID`, `*uuid.UUID`, the separate module `github.com/insei/valigo/rules/uuid` | `Required`, `AnyOf` |
| `str.Slice`, `num.Slice`, `timex.Slice`, `eq.Slice`, `vuuid.Slice` | slices, also of pointers | `Required`, `MinLen`, `MaxLen`, `Each` for the elements, `Unique` |
| `b.Map(&m.X)` | maps | `Required`, `MinLen`, `MaxLen`, `EachKey`, `EachValue` |

Expand Down
4 changes: 2 additions & 2 deletions bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
playground "github.com/go-playground/validator/v10"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
)

type Address struct {
Expand Down
4 changes: 2 additions & 2 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/stretchr/testify/require"

"github.com/insei/valigo/internal/testenv"
"github.com/insei/valigo/num"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
)

type status string
Expand Down
6 changes: 3 additions & 3 deletions constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"github.com/stretchr/testify/assert"

"github.com/insei/valigo/eq"
"github.com/insei/valigo/num"
"github.com/insei/valigo/rules/eq"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
)

type constraintsAddress struct {
Expand Down
4 changes: 2 additions & 2 deletions docs/architecture/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ The rules append their errors to one pooled buffer of the validation, and `Valid
| `valigo` | `Validator`, `Configure`, `Configurator` with `Field`, `Slice`, `Map`, `When`, `Custom` and `Tags`, options |
| `internal/zero`, `internal/helper`, `internal/tags` | the allocation of the models of `Configure`, the helper of the errors with the translator and the locations, the rules of the tags |
| `shared` | the rules core `Field[T]`, slice configurator and `Elems[E]`, `As` and the conversions `Deref`, `Retype`, `RetypeSlice`, `SlicePtr`, `SliceRules`, `Error`, helpers |
| `str`, `num`, `timex`, `eq` | configurators of strings, numbers, times and comparable values built on `shared.Field[T]`, their conversions `str.Of`, `num.Of`, `num.Ptr`, `timex.Of`, `eq.Of`... and slice conversions |
| `rules/str`, `rules/num`, `rules/timex`, `rules/eq` | configurators of strings, numbers, times and comparable values built on `shared.Field[T]`, their conversions `str.Of`, `num.Of`, `num.Ptr`, `timex.Of`, `eq.Of`... and slice conversions |
| `problem` | the problem details of RFC 9457 |
| `github.com/insei/valigo/uuid` | the separate module with the rules of `github.com/google/uuid`, the core doesn't depend on a uuid package |
| `github.com/insei/valigo/rules/uuid` | the separate module with the rules of `github.com/google/uuid`, the core doesn't depend on a uuid package |
| `github.com/insei/valigo/huma` | the separate module of the inputs of huma operations |
| `translator` | translator, in-memory storage, built-in locales, `Accept-Language` middleware |

Expand Down
4 changes: 2 additions & 2 deletions docs/features/absent.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
)

type Address struct {
Expand Down
6 changes: 3 additions & 3 deletions docs/features/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
)

type Sender struct {
Expand Down Expand Up @@ -79,8 +79,8 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
)

type Customer struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/str"
)

type Address struct {
Expand Down
4 changes: 2 additions & 2 deletions docs/features/conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ b.Field(&u.Age).As(str.Of)
| `num.Ptr` | pointers to numbers | [numbers](numbers.md), `Required` checks only that the pointer isn't nil |
| `timex.Of` | `time.Time`, `*time.Time` | [time](time.md) |
| `eq.Of`, `eq.Ptr` | any `comparable` type and pointers to it: enums, `bool` | [comparable values](values.md) |
| `vuuid.Of` | `uuid.UUID`, `*uuid.UUID` of `github.com/google/uuid` | [uuid](uuid.md), the separate module `github.com/insei/valigo/uuid` |
| `vuuid.Of` | `uuid.UUID`, `*uuid.UUID` of `github.com/google/uuid` | [uuid](uuid.md), the separate module `github.com/insei/valigo/rules/uuid` |
| `str.Slice` | `Slice` of strings, `*string` or named strings | [slices](slices.md) with the string rules of elements |
| `timex.Slice` | `Slice` of `time.Time`, `*time.Time` | [slices](slices.md) with the time rules of elements |
| `eq.Slice` | `Slice` of a `comparable` type | [slices](slices.md) with `Unique` and the equality rules of elements |
Expand Down Expand Up @@ -126,4 +126,4 @@ Output:
[Should be after 2026-01-01 (EndsAt: 2025-12-31 00:00:00 +0000 UTC)]
```

The type constraint of `TimeOf` makes `b.Field(&e.Title).As(TimeOf)` a compile error for a `string` field. The rules of another uuid package are added the same way, see the source of [`github.com/insei/valigo/uuid`](https://github.com/Insei/valigo/tree/main/uuid).
The type constraint of `TimeOf` makes `b.Field(&e.Title).As(TimeOf)` a compile error for a `string` field. The rules of another uuid package are added the same way, see the source of [`github.com/insei/valigo/rules/uuid`](https://github.com/Insei/valigo/tree/main/rules/uuid).
6 changes: 3 additions & 3 deletions docs/features/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"strings"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
)

type Account struct {
Expand Down Expand Up @@ -132,8 +132,8 @@ import (
"unicode/utf8"

"github.com/insei/valigo"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
)

type tenantKey struct{}
Expand Down
2 changes: 1 addition & 1 deletion docs/features/echo.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

"github.com/insei/valigo"
vecho "github.com/insei/valigo/echo"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
"github.com/labstack/echo/v4"
)

Expand Down
8 changes: 4 additions & 4 deletions docs/features/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import (
"time"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/str"
"github.com/insei/valigo/timex"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/rules/timex"
)

type Event struct {
Expand Down Expand Up @@ -121,7 +121,7 @@ import (

"github.com/insei/fmap/v3"
"github.com/insei/valigo"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/str"
)

type Address struct {
Expand Down
6 changes: 3 additions & 3 deletions docs/features/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
"time"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/str"
"github.com/insei/valigo/timex"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/rules/timex"
)

type Auction struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/gin.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"github.com/insei/valigo"
vgin "github.com/insei/valigo/gin"
"github.com/insei/valigo/problem"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
)

type SignUp struct {
Expand Down
6 changes: 3 additions & 3 deletions docs/features/huma.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import (
"github.com/danielgtaylor/huma/v2/adapters/humago"
"github.com/insei/valigo"
vhuma "github.com/insei/valigo/huma"
"github.com/insei/valigo/num"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
)

type CreateUserInput struct {
Expand Down Expand Up @@ -135,7 +135,7 @@ import (
"github.com/danielgtaylor/huma/v2/adapters/humago"
"github.com/insei/valigo"
vhuma "github.com/insei/valigo/huma"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/str"
)

type CreateUserInput struct {
Expand Down
4 changes: 2 additions & 2 deletions docs/features/maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
)

type Service struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/rules/num"
)

type UpdateProduct struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/insei/fmap/v3"
"github.com/insei/valigo"
"github.com/insei/valigo/problem"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/translator"
)

Expand Down
4 changes: 2 additions & 2 deletions docs/features/slices.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (

"github.com/google/uuid"
"github.com/insei/valigo"
"github.com/insei/valigo/rules/str"
vuuid "github.com/insei/valigo/rules/uuid"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
vuuid "github.com/insei/valigo/uuid"
)

type Post struct {
Expand Down
4 changes: 2 additions & 2 deletions docs/features/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/str"
)

type Webhook struct {
Expand Down Expand Up @@ -136,7 +136,7 @@ import (
"regexp"

"github.com/insei/valigo"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/str"
)

type Product struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/str"
)

type Address struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
"time"

"github.com/insei/valigo"
"github.com/insei/valigo/timex"
"github.com/insei/valigo/rules/timex"
)

type Report struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/insei/valigo/str"
"github.com/insei/valigo/translator"
)

Expand Down
8 changes: 4 additions & 4 deletions docs/features/uuid.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# UUID

The rules of [`github.com/google/uuid`](https://pkg.go.dev/github.com/google/uuid) are in the separate module `github.com/insei/valigo/uuid`, so the core doesn't depend on a uuid package:
The rules of [`github.com/google/uuid`](https://pkg.go.dev/github.com/google/uuid) are in the separate module `github.com/insei/valigo/rules/uuid`, so the core doesn't depend on a uuid package:

```bash
go get github.com/insei/valigo/uuid@latest
go get github.com/insei/valigo/rules/uuid@latest
```

`uuid.Of` converts a `uuid.UUID` field or a `*uuid.UUID` field to the uuid configurator, `uuid.Slice` — a slice of them. The module's package is also named `uuid`, import it with an alias next to `github.com/google/uuid`:

```go
import (
"github.com/google/uuid"
vuuid "github.com/insei/valigo/uuid"
vuuid "github.com/insei/valigo/rules/uuid"
)

type Comment struct {
Expand Down Expand Up @@ -46,8 +46,8 @@ import (

"github.com/google/uuid"
"github.com/insei/valigo"
vuuid "github.com/insei/valigo/rules/uuid"
"github.com/insei/valigo/shared"
vuuid "github.com/insei/valigo/uuid"
)

type Comment struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/values.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (
"fmt"

"github.com/insei/valigo"
"github.com/insei/valigo/eq"
"github.com/insei/valigo/rules/eq"
)

type Plan string
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"regexp"

"github.com/insei/valigo"
"github.com/insei/valigo/num"
"github.com/insei/valigo/str"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
)

type User struct {
Expand Down
Loading
Loading