Home / Function/ Test_Bind_Query_WithSetParserDecoder() — fiber Function Reference

Test_Bind_Query_WithSetParserDecoder() — fiber Function Reference

Architecture documentation for the Test_Bind_Query_WithSetParserDecoder() function in bind_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  d390e8e0_c38a_6145_9183_c9be0978a1a7["Test_Bind_Query_WithSetParserDecoder()"]
  55065b01_f5dc_4e53_5a74_5ecc7aca8f52["bind_test.go"]
  d390e8e0_c38a_6145_9183_c9be0978a1a7 -->|defined in| 55065b01_f5dc_4e53_5a74_5ecc7aca8f52
  style d390e8e0_c38a_6145_9183_c9be0978a1a7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

bind_test.go lines 173–222

func Test_Bind_Query_WithSetParserDecoder(t *testing.T) {
	type NonRFCTime time.Time

	nonRFCConverter := func(value string) reflect.Value {
		if v, err := time.Parse("2006-01-02", value); err == nil {
			return reflect.ValueOf(v)
		}
		return reflect.Value{}
	}

	nonRFCTime := binder.ParserType{
		CustomType: NonRFCTime{},
		Converter:  nonRFCConverter,
	}

	binder.SetParserDecoder(binder.ParserConfig{
		IgnoreUnknownKeys: true,
		ParserType:        []binder.ParserType{nonRFCTime},
		ZeroEmpty:         true,
		SetAliasTag:       "query",
	})

	app := New()
	c := app.AcquireCtx(&fasthttp.RequestCtx{})

	type NonRFCTimeInput struct {
		Date  NonRFCTime `query:"date"`
		Title string     `query:"title"`
		Body  string     `query:"body"`
	}

	c.Request().SetBody([]byte(``))
	c.Request().Header.SetContentType("")
	q := new(NonRFCTimeInput)

	c.Request().URI().SetQueryString("date=2021-04-10&title=CustomDateTest&Body=October")
	require.NoError(t, c.Bind().Query(q))
	require.Equal(t, "CustomDateTest", q.Title)
	date := fmt.Sprintf("%v", q.Date)
	require.Equal(t, "{0 63753609600 <nil>}", date)
	require.Equal(t, "October", q.Body)

	c.Request().URI().SetQueryString("date=2021-04-10&title&Body=October")
	q = &NonRFCTimeInput{
		Title: "Existing title",
		Body:  "Existing Body",
	}
	require.NoError(t, c.Bind().Query(q))
	require.Empty(t, q.Title)
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_Bind_Query_WithSetParserDecoder() do?
Test_Bind_Query_WithSetParserDecoder() is a function in the fiber codebase, defined in bind_test.go.
Where is Test_Bind_Query_WithSetParserDecoder() defined?
Test_Bind_Query_WithSetParserDecoder() is defined in bind_test.go at line 173.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free