http urls monitor.

text.go 760B

12345678910111213141516171819202122232425262728293031323334353637
  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. package render
  5. import (
  6. "fmt"
  7. "io"
  8. "net/http"
  9. )
  10. type String struct {
  11. Format string
  12. Data []interface{}
  13. }
  14. var plainContentType = []string{"text/plain; charset=utf-8"}
  15. func (r String) Render(w http.ResponseWriter) error {
  16. WriteString(w, r.Format, r.Data)
  17. return nil
  18. }
  19. func (r String) WriteContentType(w http.ResponseWriter) {
  20. writeContentType(w, plainContentType)
  21. }
  22. func WriteString(w http.ResponseWriter, format string, data []interface{}) {
  23. writeContentType(w, plainContentType)
  24. if len(data) > 0 {
  25. fmt.Fprintf(w, format, data...)
  26. } else {
  27. io.WriteString(w, format)
  28. }
  29. }