1
0
mirror of https://github.com/labstack/echo.git synced 2025-03-23 21:29:26 +02:00

minor refactor, #677

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-10-25 08:08:46 -07:00
parent b2479c275d
commit 2fbaf3a363
2 changed files with 10 additions and 7 deletions

View File

@ -421,10 +421,13 @@ func (c *context) XML(code int, i interface{}) (err error) {
}
func (c *context) XMLBlob(code int, b []byte) (err error) {
c.response.Header().Set(HeaderContentType, MIMEApplicationXMLCharsetUTF8)
c.response.WriteHeader(code)
if _, err = c.response.Write([]byte(xml.Header)); err != nil {
return
}
return c.Blob(code, MIMEApplicationXMLCharsetUTF8, b)
_, err = c.response.Write(b)
return
}
func (c *context) Blob(code int, contentType string, b []byte) (err error) {

View File

@ -48,7 +48,7 @@ type (
template *fasttemplate.Template
color *color.Color
bufferPool sync.Pool
pool sync.Pool
}
)
@ -89,7 +89,7 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
if w, ok := config.Output.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {
config.color.Disable()
}
config.bufferPool = sync.Pool{
config.pool = sync.Pool{
New: func() interface{} {
return bytes.NewBuffer(make([]byte, 256))
},
@ -108,9 +108,9 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
c.Error(err)
}
stop := time.Now()
buf := config.bufferPool.Get().(*bytes.Buffer)
buf := config.pool.Get().(*bytes.Buffer)
buf.Reset()
defer config.bufferPool.Put(buf)
defer config.pool.Put(buf)
_, err = config.template.ExecuteFunc(buf, func(w io.Writer, tag string) (int, error) {
switch tag {