Skip to content

Commit

Permalink
chore: replace vendored gorilla/schema package
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Sep 30, 2024
1 parent 44cd700 commit 2f6a850
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 1,364 deletions.
4 changes: 4 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func Test_Bind_Query(t *testing.T) {
No []int64
ID int
Bool bool
Default string `query:"default,default:hello"`
Defaults []string `query:"defaults,default:hello|world"`
}

c.Request().URI().SetQueryString("id=1&name=tom&hobby=basketball,football&favouriteDrinks=milo,coke,pepsi&alloc=&no=1")
Expand All @@ -76,6 +78,8 @@ func Test_Bind_Query(t *testing.T) {
require.Equal(t, nilSlice, q2.Empty)
require.Equal(t, []string{""}, q2.Alloc)
require.Equal(t, []int64{1}, q2.No)
require.Equal(t, "hello", q2.Default)
require.Equal(t, []string{"hello", "world"}, q2.Defaults)

type RequiredQuery struct {
Name string `query:"name,required"`
Expand Down
2 changes: 1 addition & 1 deletion binder/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/gofiber/utils/v2"
"github.com/valyala/bytebufferpool"

"github.com/gofiber/fiber/v3/internal/schema"
"github.com/gofiber/schema"
)

// ParserConfig form decoder config for SetParserDecoder
Expand Down
37 changes: 37 additions & 0 deletions docs/api/bind.md
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,40 @@ app.Post("/", func(c fiber.Ctx) error {
}
})
```

## Default Fields

You can set default values for fields in the struct by using the `default` struct tag. Supported types:
- bool

Check failure on line 580 in docs/api/bind.md

View workflow job for this annotation

GitHub Actions / markdownlint

Lists should be surrounded by blank lines

docs/api/bind.md:580 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- bool"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md032.md
- float variants (float32, float64)
- int variants (int, int8, int16, int32, int64)
- uint variants (uint, uint8, uint16, uint32, uint64)
- string
- a slice of the above types. As shown in the example above, **| should be used to separate between slice items**.
- a pointer to one of the above types **(pointer to slice and slice of pointers are not supported)**.


Check failure on line 588 in docs/api/bind.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines

docs/api/bind.md:588 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md012.md
```go title="Example"
type Person struct {
Name string `query:"name,default:john"`
Pass string `query:"pass"`
Products []string `query:"products,default:shoe|hat"`
}

app.Get("/", func(c fiber.Ctx) error {
p := new(Person)

if err := c.Bind().Query(p); err != nil {
return err
}

log.Println(p.Name) // john
log.Println(p.Pass) // doe
log.Println(p.Products) // ["shoe,hat"]

// ...
})
// Run tests with the following curl command

// curl "http://localhost:3000/?pass=doe"
```

Check failure on line 612 in docs/api/bind.md

View workflow job for this annotation

GitHub Actions / markdownlint

Files should end with a single newline character

docs/api/bind.md:612:3 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md047.md
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"

"github.com/gofiber/fiber/v3/internal/schema"
"github.com/gofiber/schema"
)

// Wrap and return this for unreachable code if panicking is undesirable (i.e., in a handler).
Expand Down
2 changes: 1 addition & 1 deletion error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"testing"

"github.com/gofiber/fiber/v3/internal/schema"
"github.com/gofiber/schema"
"github.com/stretchr/testify/require"
)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofiber/schema v0.0.0-20240930192558-a38168951d4b // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/schema v0.0.0-20240930192558-a38168951d4b h1:V18jx4lrq1QwBHKfQpiEAezWxlMLwBA5WRuwx7A1Mjo=
github.com/gofiber/schema v0.0.0-20240930192558-a38168951d4b/go.mod h1:YYwj01w3hVfaNjhtJzaqetymL56VW642YS3qZPhuE6c=
github.com/gofiber/utils/v2 v2.0.0-beta.6 h1:ED62bOmpRXdgviPlfTmf0Q+AXzhaTUAFtdWjgx+XkYI=
github.com/gofiber/utils/v2 v2.0.0-beta.6/go.mod h1:3Kz8Px3jInKFvqxDzDeoSygwEOO+3uyubTmUa6PqY+0=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down
27 changes: 0 additions & 27 deletions internal/schema/LICENSE

This file was deleted.

Loading

0 comments on commit 2f6a850

Please sign in to comment.