From 41e7b29ba2e363d5f7c7611cef5a86537595456e Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Sat, 15 Jul 2017 21:13:21 -0400 Subject: [PATCH] TIL io.WriteString --- engine.go | 4 ++-- render/context_test.go | 8 ++++---- render/render.go | 6 +++--- tags/include_tag.go | 2 +- tags/iteration_tags.go | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/engine.go b/engine.go index 0f32493..bb21ff5 100644 --- a/engine.go +++ b/engine.go @@ -28,7 +28,7 @@ func (e *Engine) RegisterBlock(name string, td Renderer) { if err != nil { return err } - _, err = w.Write([]byte(s)) + _, err = io.WriteString(w, s) return err }) } @@ -60,7 +60,7 @@ func (e *Engine) RegisterTag(name string, td Renderer) { if err != nil { return err } - _, err = w.Write([]byte(s)) + _, err = io.WriteString(w, s) return err }, nil }) diff --git a/render/context_test.go b/render/context_test.go index 550ac79..be3cdfa 100644 --- a/render/context_test.go +++ b/render/context_test.go @@ -16,19 +16,19 @@ func addContextTestTags(s Config) { if err != nil { return err } - _, err = w.Write([]byte(fmt.Sprint(v))) + _, err = fmt.Fprint(w, v) return err }) s.AddBlock("parse").Compiler(func(c BlockNode) (func(io.Writer, Context) error, error) { a := c.Args return func(w io.Writer, c Context) error { - _, err := w.Write([]byte(a)) + _, err := io.WriteString(w, a) return err }, nil }) s.AddTag("tag_name", func(string) (func(io.Writer, Context) error, error) { return func(w io.Writer, c Context) error { - _, err := w.Write([]byte(c.TagName())) + _, err := io.WriteString(w, c.TagName()) return err }, nil }) @@ -38,7 +38,7 @@ func addContextTestTags(s Config) { if err != nil { return err } - _, err = w.Write([]byte(s)) + _, err = io.WriteString(w, s) return err }, nil }) diff --git a/render/render.go b/render/render.go index 01cd18e..5e5b423 100644 --- a/render/render.go +++ b/render/render.go @@ -30,7 +30,7 @@ func (n *BlockNode) render(w io.Writer, ctx nodeContext) Error { func (n *RawNode) render(w io.Writer, ctx nodeContext) Error { for _, s := range n.slices { - _, err := w.Write([]byte(s)) + _, err := io.WriteString(w, s) if err != nil { return wrapRenderError(err, n) } @@ -60,7 +60,7 @@ func (n *TagNode) render(w io.Writer, ctx nodeContext) Error { } func (n *TextNode) render(w io.Writer, ctx nodeContext) Error { - _, err := w.Write([]byte(n.Source)) + _, err := io.WriteString(w, n.Source) return wrapRenderError(err, n) } @@ -83,7 +83,7 @@ func writeObject(value interface{}, w io.Writer) error { } return nil default: - _, err := w.Write([]byte(fmt.Sprint(value))) + _, err := io.WriteString(w, fmt.Sprint(value)) return err } } diff --git a/tags/include_tag.go b/tags/include_tag.go index 76108d4..6442a24 100644 --- a/tags/include_tag.go +++ b/tags/include_tag.go @@ -25,7 +25,7 @@ func includeTag(source string) (func(io.Writer, render.Context) error, error) { if err != nil { return err } - _, err = w.Write([]byte(s)) + _, err = io.WriteString(w, s) return err }, nil } diff --git a/tags/iteration_tags.go b/tags/iteration_tags.go index a2f776a..6240c39 100644 --- a/tags/iteration_tags.go +++ b/tags/iteration_tags.go @@ -51,7 +51,7 @@ func cycleTag(args string) (func(io.Writer, render.Context) error, error) { n := cycleMap[group] cycleMap[group] = n + 1 // The parser guarantees that there will be at least one item. - _, err = w.Write([]byte(values[n%len(values)])) + _, err = io.WriteString(w, values[n%len(values)]) return err }, nil }