From ce991b4d8597e75776febb818abc2c053b540b63 Mon Sep 17 00:00:00 2001 From: sentriz Date: Wed, 4 Oct 2023 20:54:42 +0100 Subject: [PATCH] use sync.Pool instead of bpool --- go.mod | 1 - go.sum | 2 -- server/ctrladmin/ctrl.go | 9 ++++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 14ab40a..d61d360 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 316f5b2..059c464 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/server/ctrladmin/ctrl.go b/server/ctrladmin/ctrl.go index b2a5214..5b9fa78 100644 --- a/server/ctrladmin/ctrl.go +++ b/server/ctrladmin/ctrl.go @@ -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