1// Copyright 2014 Manu Martinez-Almeida. All rights reserved. 2// Use of this source code is governed by a MIT style 3// license that can be found in the LICENSE file. 4 5package render 6 7import ( 8 "fmt" 9 "io" 10 "net/http" 11) 12 13type String struct { 14 Format string 15 Data []interface{} 16} 17 18var plainContentType = []string{"text/plain; charset=utf-8"} 19 20func (r String) Render(w http.ResponseWriter) error { 21 WriteString(w, r.Format, r.Data) 22 return nil 23} 24 25func (r String) WriteContentType(w http.ResponseWriter) { 26 writeContentType(w, plainContentType) 27} 28 29func WriteString(w http.ResponseWriter, format string, data []interface{}) { 30 writeContentType(w, plainContentType) 31 if len(data) > 0 { 32 fmt.Fprintf(w, format, data...) 33 } else { 34 io.WriteString(w, format) 35 } 36} 37