Skip to content

Commit

Permalink
clear go template generated black lines
Browse files Browse the repository at this point in the history
  • Loading branch information
coldstar committed Jan 31, 2019
1 parent 14ab7a6 commit 4969aec
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package baa

import (
"bufio"
"bytes"
"encoding/xml"
"errors"
Expand Down Expand Up @@ -532,7 +533,24 @@ func (c *Context) Fetch(tpl string) ([]byte, error) {
if err := c.baa.Render().Render(buf, tpl, c.Gets()); err != nil {
return nil, err
}
return buf.Bytes(), nil

// clear go template generated black lines
nbuf := new(bytes.Buffer)
r := bufio.NewReader(buf)
for {
line, _, err := r.ReadLine()
if err != nil {
break
}
clearLine := strings.TrimSpace(string(line))
if len(clearLine) == 0 {
continue
}
nbuf.Write(line)
nbuf.WriteRune('\n')
}

return nbuf.Bytes(), nil
}

// Redirect redirects the request using http.Redirect with status code.
Expand Down

0 comments on commit 4969aec

Please sign in to comment.