github.com/wanliu/go-oauth2-server@v0.0.0-20180817021415-f928fa1580df/web/string_builder.go (about)

     1  package web
     2  
     3  import (
     4  	"bytes"
     5  	"html/template"
     6  	"strings"
     7  )
     8  
     9  type StringBuilder []string
    10  
    11  func (sb *StringBuilder) Append(s string) {
    12  	*sb = append(*sb, s)
    13  }
    14  
    15  func (sb *StringBuilder) Join(s *StringBuilder) {
    16  	*sb = append(*sb, *s...)
    17  }
    18  
    19  func (sb *StringBuilder) String() string {
    20  	return strings.Join(*sb, "")
    21  }
    22  
    23  func (sb *StringBuilder) AddTemplate(t *template.Template, name string, data interface{}) error {
    24  	buf := &bytes.Buffer{}
    25  	err := t.ExecuteTemplate(buf, name, data)
    26  	if err != nil {
    27  		return err
    28  	}
    29  	sb.Append(buf.String())
    30  	return nil
    31  }