aboutsummaryrefslogtreecommitdiff
path: root/internal/toolkit/toolkit.go
diff options
context:
space:
mode:
authorBrian Picciano <me@mediocregopher.com>2024-11-01 13:00:18 +0100
committerBrian Picciano <me@mediocregopher.com>2024-11-01 13:00:18 +0100
commitcf6af6def1cac3fc6cd044c82282208b7073eb64 (patch)
tree64d6186b5e30e1125c1eff6fa1d86a379e3d3693 /internal/toolkit/toolkit.go
parent246a99c28980e985bb4cff99042459bd5729cde1 (diff)
Implement gemtext HTTP middleware
Diffstat (limited to 'internal/toolkit/toolkit.go')
-rw-r--r--internal/toolkit/toolkit.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/toolkit/toolkit.go b/internal/toolkit/toolkit.go
new file mode 100644
index 0000000..f87a496
--- /dev/null
+++ b/internal/toolkit/toolkit.go
@@ -0,0 +1,23 @@
+// Package toolkit contains useful, general-purpose utilities
+package toolkit
+
+import (
+ "bytes"
+ "sync"
+)
+
+var bufPool = sync.Pool{
+ New: func() any {
+ return new(bytes.Buffer)
+ },
+}
+
+// GetBuffer returns an empty buffer, along with a function which can be used to
+// return it to a global pool, which helps reduce allocations.
+func GetBuffer() (*bytes.Buffer, func()) {
+ buf := bufPool.Get().(*bytes.Buffer)
+ return buf, func() {
+ buf.Reset()
+ bufPool.Put(buf)
+ }
+}