Home / Function/ Test_Bind_Header_WithSetParserDecoder() — fiber Function Reference

Test_Bind_Header_WithSetParserDecoder() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

bind_test.go lines 427–479

func Test_Bind_Header_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:       "req",
	})

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

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

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

	c.Request().Header.Add("Date", "2021-04-10")
	c.Request().Header.Add("Title", "CustomDateTest")
	c.Request().Header.Add("Body", "October")

	require.NoError(t, c.Bind().Header(r))
	require.Equal(t, "CustomDateTest", r.Title)
	date := fmt.Sprintf("%v", r.Date)
	require.Equal(t, "{0 63753609600 <nil>}", date)
	require.Equal(t, "October", r.Body)

	c.Request().Header.Add("Title", "")
	r = &NonRFCTimeInput{
		Title: "Existing title",
		Body:  "Existing Body",
	}
	require.NoError(t, c.Bind().Header(r))
	require.Empty(t, r.Title)
}

Domain

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free