The middleware has been archived, please use the middleware of elton.
Body parser for elton. It support application/json
and application/x-www-form-urlencoded
type, but NewDefault
just support application/json
.
package main
import (
"bytes"
"github.com/vicanso/elton"
bodyparser "github.com/vicanso/elton-body-parser"
)
func main() {
e := elton.New()
e.Use(bodyparser.NewDefault())
e.POST("/user/login", func(c *elton.Context) (err error) {
c.BodyBuffer = bytes.NewBuffer(c.RequestBody)
return
})
e.ListenAndServe(":3000")
}
create a new default body parser middleware. It include gzip and json decoder.
e.Use(bodyparser.NewDefault())
create a new gzip decoder
conf := bodyparser.Config{}
conf.AddDecoder(bodyparser.NewGzipDecoder())
e.Use(bodyparser.New(conf))
create a new json decoder
conf := bodyparser.Config{}
conf.AddDecoder(bodyparser.NewJSONDecoder())
e.Use(bodyparser.New(conf))
create a new form url encoded decoder
conf := bodyparser.Config{
ContentTypeValidate: bodyparser.DefaultJSONAndFormContentTypeValidate
}
conf.AddDecoder(bodyparser.NewFormURLEncodedDecoder())
e.Use(bodyparser.New(conf))