Test_Bind_Body_WithSetParserDecoder() — fiber Function Reference
Architecture documentation for the Test_Bind_Body_WithSetParserDecoder() function in bind_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD aba66e5c_1ee4_68f6_f037_03f7d3a40537["Test_Bind_Body_WithSetParserDecoder()"] 55065b01_f5dc_4e53_5a74_5ecc7aca8f52["bind_test.go"] aba66e5c_1ee4_68f6_f037_03f7d3a40537 -->|defined in| 55065b01_f5dc_4e53_5a74_5ecc7aca8f52 style aba66e5c_1ee4_68f6_f037_03f7d3a40537 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
bind_test.go lines 1100–1148
func Test_Bind_Body_WithSetParserDecoder(t *testing.T) {
type CustomTime time.Time
timeConverter := func(value string) reflect.Value {
if v, err := time.Parse("2006-01-02", value); err == nil {
return reflect.ValueOf(v)
}
return reflect.Value{}
}
customTime := binder.ParserType{
CustomType: CustomTime{},
Converter: timeConverter,
}
binder.SetParserDecoder(binder.ParserConfig{
IgnoreUnknownKeys: true,
ParserType: []binder.ParserType{customTime},
ZeroEmpty: true,
SetAliasTag: "form",
})
app := New()
c := app.AcquireCtx(&fasthttp.RequestCtx{})
type Demo struct {
Date CustomTime `form:"date"`
Title string `form:"title"`
Body string `form:"body"`
}
testDecodeParser := func(contentType, body string) {
c.Request().Header.SetContentType(contentType)
c.Request().SetBody([]byte(body))
c.Request().Header.SetContentLength(len(body))
d := Demo{
Title: "Existing title",
Body: "Existing Body",
}
require.NoError(t, c.Bind().Body(&d))
date := fmt.Sprintf("%v", d.Date)
require.Equal(t, "{0 63743587200 <nil>}", date)
require.Empty(t, d.Title)
require.Equal(t, "New Body", d.Body)
}
testDecodeParser(MIMEApplicationForm, "date=2020-12-15&title=&body=New Body")
testDecodeParser(MIMEMultipartForm+`; boundary="b"`, "--b\r\nContent-Disposition: form-data; name=\"date\"\r\n\r\n2020-12-15\r\n--b\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n\r\n--b\r\nContent-Disposition: form-data; name=\"body\"\r\n\r\nNew Body\r\n--b--")
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Bind_Body_WithSetParserDecoder() do?
Test_Bind_Body_WithSetParserDecoder() is a function in the fiber codebase, defined in bind_test.go.
Where is Test_Bind_Body_WithSetParserDecoder() defined?
Test_Bind_Body_WithSetParserDecoder() is defined in bind_test.go at line 1100.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free