func BodyLimitWithConfig(config BodyLimitConfig) nio.MiddlewareFunc {
	if config.Skipper == nil {
		config.Skipper = DefaultBodyLimitConfig.Skipper
	}
	limit, err := bytes.Parse(config.Limit)
	if err != nil {
		panic(fmt.Errorf("nio: invalid body-limit=%s", config.Limit))
	}
	config.limit = limit
	pool := limitedReaderPool(config)
	return func(next nio.HandlerFunc) nio.HandlerFunc {
		return func(c nio.Context) error {
			if config.Skipper(c) {
				return next(c)
			}
			req := c.Request()
			if req.ContentLength > config.limit {
				return nio.ErrStatusRequestEntityTooLarge
			}
			r := pool.Get().(*limitedReader)
			r.Reset(req.Body, c)
			defer pool.Put(r)
			req.Body = r
			return next(c)
		}
	}
}
BodyLimitWithConfig returns a BodyLimit middleware with config.
See: `BodyLimit()`.
package mw
import (
	"fmt"
	"io"
	"sync"
	"github.com/go-nio/nio"
	"github.com/go-nio/nio/internal/bytes"
)
type (
	BodyLimitConfig struct {
		Skipper nio.Skipper
		Limit string `yaml:"limit"`
		limit int64
	}
	limitedReader struct {
		BodyLimitConfig
		reader  io.ReadCloser
		read    int64
		context nio.Context
	}
)
var (
	DefaultBodyLimitConfig = BodyLimitConfig{
		Skipper: nio.DefaultSkipper,
	}
)
func BodyLimit(limit string) nio.MiddlewareFunc {
	c := DefaultBodyLimitConfig
	c.Limit = limit
	return BodyLimitWithConfig(c)
}