mirror of https://github.com/gofiber/fiber.git
parent
385c94adcd
commit
670170f7c5
10
app.go
10
app.go
|
@ -308,6 +308,13 @@ type Config struct {
|
|||
// Default: json.Marshal
|
||||
JSONEncoder utils.JSONMarshal `json:"-"`
|
||||
|
||||
// When set by an external client of Fiber it will use the provided implementation of a
|
||||
// JSONUnmarshal
|
||||
//
|
||||
// Allowing for flexibility in using another json library for encoding
|
||||
// Default: json.Unmarshal
|
||||
JSONDecoder utils.JSONUnmarshal `json:"-"`
|
||||
|
||||
// Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only)
|
||||
// WARNING: When prefork is set to true, only "tcp4" and "tcp6" can be chose.
|
||||
//
|
||||
|
@ -459,6 +466,9 @@ func New(config ...Config) *App {
|
|||
if app.config.JSONEncoder == nil {
|
||||
app.config.JSONEncoder = json.Marshal
|
||||
}
|
||||
if app.config.JSONDecoder == nil {
|
||||
app.config.JSONDecoder = json.Unmarshal
|
||||
}
|
||||
if app.config.Network == "" {
|
||||
app.config.Network = NetworkTCP4
|
||||
}
|
||||
|
|
2
ctx.go
2
ctx.go
|
@ -291,7 +291,7 @@ func (c *Ctx) BodyParser(out interface{}) error {
|
|||
// Parse body accordingly
|
||||
if strings.HasPrefix(ctype, MIMEApplicationJSON) {
|
||||
schemaDecoder.SetAliasTag("json")
|
||||
return json.Unmarshal(c.Body(), out)
|
||||
return c.app.config.JSONDecoder(c.Body(), out)
|
||||
}
|
||||
if strings.HasPrefix(ctype, MIMEApplicationForm) {
|
||||
schemaDecoder.SetAliasTag("form")
|
||||
|
|
Loading…
Reference in New Issue