From cf6af6def1cac3fc6cd044c82282208b7073eb64 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 1 Nov 2024 13:00:18 +0100 Subject: Implement gemtext HTTP middleware --- internal/toolkit/toolkit.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 internal/toolkit/toolkit.go (limited to 'internal/toolkit/toolkit.go') 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) + } +} -- cgit v1.2.3