package l_request

import (
	"sync"
)

type RequestPool struct {
	pool sync.Pool
}

var RequestPools = &RequestPool{
	pool: sync.Pool{
		New: func() interface{} {
			return new(Request)
		},
	},
}

func (re *RequestPool) Get() *Request {
	return re.pool.Get().(*Request)
}

func (re *RequestPool) Put(r *Request) {
	re.pool.Put(r)
}

// 重置对象
func (re *RequestPool) Reset(r *Request) {
	r.Method = ""
	r.Url = ""
	r.Params = nil
	r.Headers = nil
	r.Cookies = nil
	r.Data = nil
	r.Json = nil
	r.Files = nil
	r.Raw = ""
	r.JsonByte = nil
}

func (re *RequestPool) ClearAndPut(r *Request) {
	re.Reset(r)
	re.Put(r)
}
