woodpecker/vendor/github.com/gin-gonic/gin/render/text.go

34 lines
661 B
Go
Raw Normal View History

2015-09-30 01:21:17 +00:00
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
2015-05-22 18:37:40 +00:00
package render
import (
"fmt"
2015-09-30 01:21:17 +00:00
"io"
2015-05-22 18:37:40 +00:00
"net/http"
)
type String struct {
Format string
Data []interface{}
}
2015-09-30 01:21:17 +00:00
var plainContentType = []string{"text/plain; charset=utf-8"}
func (r String) Render(w http.ResponseWriter) error {
WriteString(w, r.Format, r.Data)
return nil
}
func WriteString(w http.ResponseWriter, format string, data []interface{}) {
writeContentType(w, plainContentType)
if len(data) > 0 {
fmt.Fprintf(w, format, data...)
2015-05-22 18:37:40 +00:00
} else {
2015-09-30 01:21:17 +00:00
io.WriteString(w, format)
2015-05-22 18:37:40 +00:00
}
}