console: use strings.Builder when working with strings
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled

This is faster than bytes.Buffer.
This commit is contained in:
Vincent Bernat
2025-10-12 08:05:43 +02:00
parent c6964cb48f
commit 17b1eeea90

View File

@@ -4,7 +4,6 @@
package console package console
import ( import (
"bytes"
"fmt" "fmt"
"io" "io"
"io/fs" "io/fs"
@@ -84,8 +83,8 @@ func (c *Component) docsHandlerFunc(gc *gin.Context) {
), ),
), ),
) )
buf := &bytes.Buffer{} var buf strings.Builder
if err = md.Convert(content, buf); err != nil { if err = md.Convert(content, &buf); err != nil {
c.r.Err(err).Str("path", entry.Name()).Msg("unable to render markdown document") c.r.Err(err).Str("path", entry.Name()).Msg("unable to render markdown document")
continue continue
} }
@@ -116,8 +115,8 @@ func (c *Component) docsHandlerFunc(gc *gin.Context) {
), ),
), ),
) )
buf := &bytes.Buffer{} var buf strings.Builder
if err = md.Convert(markdown, buf); err != nil { if err = md.Convert(markdown, &buf); err != nil {
c.r.Err(err).Str("path", requestedDocument).Msg("unable to render markdown document") c.r.Err(err).Str("path", requestedDocument).Msg("unable to render markdown document")
gc.JSON(http.StatusInternalServerError, gin.H{"message": "Unable to render document."}) gc.JSON(http.StatusInternalServerError, gin.H{"message": "Unable to render document."})
return return