use sync.Pool instead of bpool

This commit is contained in:
sentriz
2023-10-04 20:54:42 +01:00
parent 97e9675dca
commit ce991b4d85
3 changed files with 6 additions and 6 deletions

1
go.mod
View File

@@ -20,7 +20,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/mmcdole/gofeed v1.2.1
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c
github.com/peterbourgon/ff v1.7.1
github.com/philippta/go-template v0.0.0-20220911145045-4556aca435e4
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be

2
go.sum
View File

@@ -121,8 +121,6 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
github.com/peterbourgon/ff v1.7.1 h1:xt1lxTG+Nr2+tFtysY7abFgPoH3Lug8CwYJMOmJRXhk=
github.com/peterbourgon/ff v1.7.1/go.mod h1:fYI5YA+3RDqQRExmFbHnBjEeWzh9TrS8rnRpEq7XIg0=

View File

@@ -1,6 +1,7 @@
package ctrladmin
import (
"bytes"
"context"
"embed"
"encoding/base64"
@@ -12,13 +13,13 @@ import (
"net/http"
"net/url"
"strings"
"sync"
"time"
"github.com/Masterminds/sprig"
"github.com/dustin/go-humanize"
"github.com/fatih/structs"
"github.com/gorilla/sessions"
"github.com/oxtoacart/bpool"
"github.com/philippta/go-template/html/template"
"github.com/sentriz/gormstore"
@@ -202,7 +203,7 @@ func respHandler(templateFS embed.FS, resolvePath func(string) string) func(next
Funcs(template.FuncMap{"path": resolvePath}).
ParseFS(templateFS, "*.tmpl", "**/*.tmpl"),
)
buffPool := bpool.NewBufferPool(64)
buffPool := sync.Pool{New: func() any { return new(bytes.Buffer) }}
return func(next handlerAdmin) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -244,8 +245,10 @@ func respHandler(templateFS embed.FS, resolvePath func(string) string) func(next
resp.data.User = user
}
buff := buffPool.Get()
buff := buffPool.Get().(*bytes.Buffer)
defer buffPool.Put(buff)
buff.Reset()
if err := tmpl.ExecuteTemplate(buff, resp.template, resp.data); err != nil {
http.Error(w, fmt.Sprintf("executing template: %v", err), 500)
return