Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query, Header Default Value Tag Feature #2699

Draft
wants to merge 30 commits into
base: v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1054478
add: QueryParser default value tag feature and struct cache for speed
muratmirgun Nov 1, 2023
8181949
Merge branch 'gofiber:master' into master
muratmirgun Nov 1, 2023
80b3a67
:memo: docs: add QueryParser defualt value docs
muratmirgun Nov 1, 2023
0afc148
:adhesive_bandage: lint: reflect type handle exhaustive disable
muratmirgun Nov 1, 2023
016c5a6
:pencil2: typo: empty line and wrong test run comment fix
muratmirgun Nov 1, 2023
4d557ee
move: query default parser main functions to utils
muratmirgun Nov 3, 2023
06a8cf8
:test_tube: test: write basic tests for util/default
muratmirgun Nov 3, 2023
257b399
:memo: docs: add DefaultValueParser config field description
muratmirgun Nov 3, 2023
ca1943e
:hammer: refactor: slice default parser optimization
muratmirgun Nov 3, 2023
b85aecc
:rocket: feat: add pointer slice support for parser and test case update
muratmirgun Nov 6, 2023
ba8eb0d
:test_tube: update header parser test files
muratmirgun Nov 7, 2023
8394b30
:memo: docs: add header parser usage with default values
muratmirgun Nov 7, 2023
662f9d6
lint: delete redundant conversion
muratmirgun Nov 9, 2023
00e4761
test: fix int assign issue on default slice parser
muratmirgun Nov 9, 2023
253b4c9
feat: add default value parser to cookie parser with tests
muratmirgun Nov 28, 2023
8b99f13
fix: codeql security fix
muratmirgun Nov 28, 2023
a869138
security: int value conversion check change for security
muratmirgun Nov 28, 2023
ad89ced
add mutex
efectn Dec 23, 2023
413f42a
fix linter
efectn Dec 23, 2023
26dd708
fix tests
efectn Dec 23, 2023
daaed0d
fix sec
efectn Dec 23, 2023
14f8a80
Merge remote-tracking branch 'upstream/master'
ReneWerner87 Jan 4, 2024
721c284
Query, Header Default Value Tag Feature #2699
ReneWerner87 Jan 4, 2024
ce98c49
Query, Header Default Value Tag Feature #2699
ReneWerner87 Jan 4, 2024
a163888
Query, Header Default Value Tag Feature #2699
ReneWerner87 Jan 4, 2024
96c39d4
Query, Header Default Value Tag Feature #2699
ReneWerner87 Jan 4, 2024
d1e3487
Query, Header Default Value Tag Feature #2699
ReneWerner87 Jan 4, 2024
a091b23
Query, Header Default Value Tag Feature #2699
ReneWerner87 Jan 4, 2024
fc9ed03
Query, Header Default Value Tag Feature #2699
ReneWerner87 Jan 5, 2024
0102600
Query, Header Default Value Tag Feature #2699
ReneWerner87 Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions app.go
Expand Up @@ -144,6 +144,12 @@ type Config struct {
// Default: false
CaseSensitive bool `json:"case_sensitive"`

// When set to true, this will add a default value tag support to all parsers.
// This will allow you to set default values for query, path, and body parameters.
//
// Default: false
DefaultValueParser bool `json:"default_value_parser"`

// When set to true, this relinquishes the 0-allocation promise in certain
// cases in order to access the handler values (e.g. request bodies) in an
// immutable fashion so that these values are available even if you return
Expand Down
12 changes: 12 additions & 0 deletions ctx.go
Expand Up @@ -506,6 +506,10 @@ func (c *Ctx) Cookies(key string, defaultValue ...string) string {

// CookieParser is used to bind cookies to a struct
func (c *Ctx) CookieParser(out interface{}) error {
if c.app.config.DefaultValueParser {
utils.SetDefaultValues(out)
}

data := make(map[string][]string)
var err error

Expand Down Expand Up @@ -1249,6 +1253,10 @@ func (c *Ctx) QueryFloat(key string, defaultValue ...float64) float64 {

// QueryParser binds the query string to a struct.
func (c *Ctx) QueryParser(out interface{}) error {
if c.app.config.DefaultValueParser {
utils.SetDefaultValues(out)
}

data := make(map[string][]string)
var err error

Expand Down Expand Up @@ -1308,6 +1316,10 @@ func parseParamSquareBrackets(k string) (string, error) {

// ReqHeaderParser binds the request header strings to a struct.
func (c *Ctx) ReqHeaderParser(out interface{}) error {
if c.app.config.DefaultValueParser {
utils.SetDefaultValues(out)
}

data := make(map[string][]string)
c.fasthttp.Request.Header.VisitAll(func(key, val []byte) {
k := c.app.getString(key)
Expand Down